简体   繁体   English

R Shiny 错误:没有可用的堆栈跟踪和无效的下标类型“列表”

[英]R Shiny error : no stack trace available and invalid subscript type 'list'

I have the following error appearing when Shiny : Warning: Error in <-: invalid subscript type 'list' [No stack trace available]我在 Shiny 时出现以下错误:警告:<-中的错误:无效的下标类型“列表”[没有可用的堆栈跟踪]

My Shiny code :我的闪亮代码:

if (interactive()) {

ui <- fluidPage(
   
   titlePanel(title = "Uploading Files"),
   
   sidebarLayout(
      sidebarPanel(
         fileInput(inputId = "file", 
                   label = "Choose xlsx File",
                   multiple = FALSE,
                   accept = ".xlsx",
                   buttonLabel = "Browse...",
                   placeholder = "No file selected"),
         conditionalPanel(
            condition = "output.file_ready",
            hr(style = "border-color : grey"),
            checkboxGroupInput(inputId = "series", label = "")
         )
      ),
      
      mainPanel(
         tableOutput("head")
      )
   )
  
)

server <- function(session, input, output) {
   
   output$file_ready <- reactive({
      return(!is.null(input$file))
   })
   outputOptions(output, "file_ready", suspendWhenHidden = FALSE)
   
   data1 <- reactive({
      validate(need(input$file,""))
      inFile <- input$file
      if (is.null(inFile))
         return(NULL)
      df1 <- read_xlsx(inFile$datapath)
      updateCheckboxGroupInput(session, "series", label = "check", choices = colnames(df1), selected = unlist(colnames(df1)))
      return(df1)    
   })
   
   
   data2 <- reactive({
      df2 <- data1() %>% select(input$series)
      return(df2)
   })
   
   output$head <- renderTable({
      req(input$file)
      data2() %>% head
   })
}

shinyApp(ui = ui, server = server)

}

enter image description here <- data在此处输入图像描述<- 数据

Why is there an error?为什么会出现错误?

becuse of error, i used unlist function but not helped it由于错误,我使用了 unlist 功能但没有帮助它

help would be greatly appreciated帮助将不胜感激

If you use readxl package and req() , where necessary, there is no issue.如果您在必要时使用readxl包和req() ,则没有问题。

library(readxl)

ui <- fluidPage(
  
  titlePanel(title = "Uploading Files"),
  
  sidebarLayout(
    sidebarPanel(
      fileInput(inputId = "file", 
                label = "Choose xlsx File",
                multiple = FALSE,
                accept = ".xlsx",
                buttonLabel = "Browse...",
                placeholder = "No file selected"),
      conditionalPanel(
        condition = "output.file_ready",
        hr(style = "border-color : grey"),
        checkboxGroupInput(inputId = "series", label = "")
      )
    ),
    
    mainPanel(
      tableOutput("head")
    )
  )
  
)

server <- function(session, input, output) {
  
  output$file_ready <- reactive({
    return(!is.null(input$file))
  })
  outputOptions(output, "file_ready", suspendWhenHidden = FALSE)
  
  data1 <- reactive({
    req(input$file)
    inFile <- input$file
    if (is.null(inFile))
      return(NULL)
    df1 <- read_excel(inFile$datapath)
    updateCheckboxGroupInput(session, "series", label = "check", choices = colnames(df1), selected = colnames(df1))
    return(df1)    
  })
  
  
  data2 <- reactive({
    req(data1(),input$series)
    df2 <- data1() %>% select(input$series)
    return(df2)
  })
  
  output$head <- renderTable({
    req(data2())
    data2() %>% head
  })
}

shinyApp(ui = ui, server = server)

输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM