I have the following error appearing when Shiny : Warning: Error in <-: invalid subscript type 'list' [No stack trace available]
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
help would be greatly appreciated
If you use readxl
package and req()
, where necessary, there is no issue.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.