我正在尝试使用浏览选项读取数据集,以从pc上传数据。之后,我想显示要使用第一列条目自动填充的文件内容。
library(shiny)
library(shinydashboard)
ui<-(fluidPage(
titlePanel("Auto Fill"),
sidebarPanel(
autoFillDF<- fileInput('file1', 'Choose xlsx file',
accept = c(".xlsx")),
# actionButton("go", "update"),
selectizeInput("p1", choices = autoFillDF$WorklistNo, selected = NULL, label = 'WorklistNo'),
selectizeInput("p2", choices = NULL, label = 'Status'),
selectizeInput("p3", choices = NULL, label = 'Plant'),
),
mainPanel(
DT::dataTableOutput('table')
)
)
)
server<-(function(input, output, session) {
updateApp <- reactive({
data <- autoFillDF
data <- data[data$WorklistNo %in% input$p1,]
updateSelectizeInput(session, 'p2', choices = data$Status, selected = data$Status, server = TRUE)
updateSelectizeInput(session, 'p3', choices = data$Plant, selected = data$Plant, server = TRUE)
data
})
shinyApp(ui = ui, server = server)
output$table <- DT::renderDataTable(
DT::datatable(updateApp())
)
})
shinyApp(ui = ui, server = server)
这是我的数据集的样子。我必须读取所有列数据。我想放WorklistNo,其余的应该自动填充。
答案 0 :(得分:1)
我试图理解您的代码和要求,并且据我所知,我试图构建一个简单的解决方案来完成它……请看一下。
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))
{
df<<-read.csv(input$file_upload$datapath,
header = TRUE)
values$upload_state <- 'uploaded'
df
}
})
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 = 'WLID')
}
else
{
data_upload_fun()
selectInput("p1", choices = df$WLID, label = 'WLID')
}
})
output$p2_ui<-renderUI({
if(is.null(values$upload_state)|| values$upload_state=='reset')
{
selectInput("p2", choices = NULL, label = 'PLANT')
}
else
{
data_upload_fun()
plant<-df[df$WLID==input$p1,2]
selectInput("p2", choices = as.list(plant), label = 'PLANT')
}
})
output$p3_ui<-renderUI({
if(is.null(values$upload_state)|| values$upload_state=='reset')
{
selectInput("p3", choices = NULL, label = 'STATUS')
}
else
{
data_upload_fun()
status<-df[df$WLID==input$p1 & df$PLANT==input$p2,3]
selectInput("p3", choices = as.list(status), label = 'STATUS')
}
})
output$selected_data_table<-renderDT({
if(is.null(values$upload_state)|| values$upload_state=='reset')
{
returnValue()
}
else
{
data_upload_fun()
data_to_show<-df[df$WLID==input$p1 & df$PLANT==input$p2 & df$STATUS== input$p3, ]
DT::datatable(data_to_show)
}
})
}
shinyApp(ui, server)
请让我知道这是否有效以及有什么需要更改的地方...