Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何使用excel文件在Shining app中自动填充数据_R_Shiny_Shinydashboard_Shinyapps - Fatal编程技术网

R 如何使用excel文件在Shining app中自动填充数据

R 如何使用excel文件在Shining app中自动填充数据,r,shiny,shinydashboard,shinyapps,R,Shiny,Shinydashboard,Shinyapps,我正在尝试使用浏览选项读取数据集,以便从pc上载数据。之后,我希望通过使用第一列条目显示要自动填充的文件内容 library(shiny) library(shinydashboard) ui<-(fluidPage( titlePanel("Auto Fill"), sidebarPanel( autoFillDF<- fileInput('file1', 'Choose xlsx file', accept = c(".xlsx")),

我正在尝试使用浏览选项读取数据集,以便从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)
库(闪亮)
图书馆(shinydashboard)

ui我试图理解您的代码和需求,根据我的理解,我试图构建一个简单的解决方案来完成它……请看一下

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)
库(闪亮)
图书馆(shinydashboard)

用户界面@ElvinMitchellToro@Damian我无法运行你现有的代码,它显示了一系列错误。您能再检查一下吗?@amrrs我已经编辑了代码。。请检查谢谢您的回答,我试图将您的代码与我的代码集成,但自动填充值仍有错误。在数据集中,我想输入一个WorklistNo值,然后自动填充其余字段,这样我们就可以忽略WLID了。而且我的文件要求仅为excel格式,对于客户机没有csv:),因此我们必须从第2页读取我们的文件column@NIrbhayMathur您可以修改代码。您也可以使用xlsx包来读取。xlsx函数仍然存在一些问题。请看一看我摆的姿势: