I am trying to read a data set using the browse option to upload data from pc. After that, I want to display file content to be automatically filled by using first column entry.
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
fluidRow(
fileInput("file_upload","Uplaod Data",buttonLabel = "Browse..",placeholder = "No file Selected")
),
fluidRow(
column(3,
uiOutput("p1_ui")
),
column(3,
uiOutput("p2_ui")
),
column(3,
uiOutput("p3_ui")
)
),
fluidRow(
column(6,
h3("Uploaded DATA"),
DTOutput("uploaded_data_table")
),
column(6,
h3("Selected DATA"),
DTOutput("selected_data_table")
)
)
)
)
server <- function(input, output,session) {
values <- reactiveValues(
upload_state = NULL
)
data_upload_fun<-eventReactive(input$file_upload,{
req(input$file_upload)
if(values$upload_state=='reset'||is.null(values$upload_state))
{
data_in<-read_xlsx(input$file_upload$datapath
)
values$upload_state <- 'uploaded'
data_in
}
})
output$uploaded_data_table <- renderDT({
DT::datatable(data_upload_fun())
})
output$p1_ui<-renderUI({
if(is.null(values$upload_state)|| values$upload_state=='reset')
{
selectInput("p1", choices = NULL, label = 'WorklistNo')
}
else
{
data_upload_fun()
selectInput("p1", choices = uploade_data$WorklistNo, label = 'WorklistNo')
}
})
output$p2_ui<-renderUI({
if(is.null(values$upload_state)|| values$upload_state=='reset')
{
selectInput("p2", choices = NULL, label = 'Status')
}
else
{
data_upload_fun()
status<-data_in[data_in$WorklistNo==input$p1,2]
selectInput("p2", choices = as.list(status), label = 'Status')
}
})
output$p3_ui<-renderUI({
if(is.null(values$upload_state)|| values$upload_state=='reset')
{
selectInput("p3", choices = NULL, label = 'Plant')
}
else
{
data_upload_fun()
plant<-data_in[data_in$WorklistNo==input$p1 & data_in$Status==input$p2,3]
selectInput("p3", choices = as.list(plant), label = 'Plant')
}
})
output$selected_data_table<-renderDT({
if(is.null(values$upload_state)|| values$upload_state=='reset')
{
returnValue()
}
else
{
data_upload_fun()
data_to_show<-data_in[data_in$WorklistNo==input$p1 & data_in$Status==input$p2 & data_in$Plant== input$p3, ]
DT::datatable(data_to_show)
}
})
}
shinyApp(ui, server)