[英]Warning: Error in cat: argument 1 (type 'list') cannot be handled by 'cat' [No stack trace available] in R shiny webtool
[英]R Shiny error : no stack trace available and invalid subscript type 'list'
我在 Shiny 时出现以下错误:警告:<-中的错误:无效的下标类型“列表”[没有可用的堆栈跟踪]
我的闪亮代码:
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)
}
在此处输入图像描述<- 数据
为什么会出现错误?
由于错误,我使用了 unlist 功能但没有帮助它
帮助将不胜感激
如果您在必要时使用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.