简体   繁体   中英

How to resolve error " Error in file : invalid 'description' argument?

I have written a Shiny code that has a dashboard with the following elements

1) Side Bar Layout 2) On clicking Tab 'view', the main panel gets populated with tabset panel 3) On clicking 'table', two selectInput should be displayed where the sheet dropdown is dependent on Table dropdown. The Datasets are read from xlsx files

library(shinydashboard)
library(leaflet)
library(ggplot2)
library(DT)
library(openxlsx)

# -----------------------------------------------------------------------------
# Dashboard UI
# -----------------------------------------------------------------------------

dataset <- c("P1-Long-Term-Unemployment-Statistics","P1-OfficeSupplies")
ui <- dashboardPage(
  dashboardHeader(
    title = "Validation Tool"
  ),
  dashboardSidebar(
    sidebarMenu(
      menuItem("View Tables", tabName = "view", icon = icon("database")),
      menuItem("Append Data", tabName = "append", icon = icon("database")),
      menuItem("Update Table", tabName = "update", icon = icon("crosshairs")),
      menuItem("Construct Table", tabName = "construct", icon = icon("fire"))
    ),

    div(style = "padding-left: 15px;padding-right: 5px; padding-top: 40px;",
        p(class = "small", "Note : This validation tools automates the mainstream process involved in creating a Master data for detailed analysis ")
    )
  ),
  dashboardBody(
    tabItems(
      # Current location ------------------------------------------------------
      tabItem(tabName = "view",
              mainPanel(
                titlePanel(h2("Explore Datasets")),fluidRow(
                  column(8,
                         selectInput("table",
                                     "Table:",
                                     dataset)
                  ),
                  column(8,
                         uiOutput("sheets")
                  ),
                  DT::dataTableOutput("table")
                ),
        tabsetPanel(type="tab", 
                    tabPanel("Data"

                             ),
                    tabPanel("Summary"),
                    tabPanel("Plot")
      )
    )
  )
)
)
)
# -----------------------------------------------------------------------------
# Dashboard server code
# -----------------------------------------------------------------------------
server <- function(input, output) {


    file <- reactive({paste0("D:/Dataset/",input$table,".xlsx")})
    sheetNames <- reactive({getSheetNames(file)})


    output$sheets <- renderUI({
    selectInput("sheet","Sheet:",choices = sheetNames)
    })

    output$table <- DT::renderDataTable(DT::datatable({    
    data <- read.xlsx(file,sheet=as.numeric(input$sheet))
    data
     }))


}


shinyApp(ui, server)

But while implementing the above, I get the error (screenshot attached)

"Error : Invalid 'description' argument" "Error : cannot coerce type 'closure' to vector of type 'list'

Please help resolving the issue

You have to call reactive values with parentheses ( file reactive value declared in line 62). But there is a file() function in base R, so change this eg for my_file and call it with parentheses, eg:

my_file <- reactive({paste0("D:/Dataset/",input$table,".xlsx")})
sheetNames <- reactive({getSheetNames(my_file())})

The below code works fine

server <- function(input, output) {

  my_file <- function(){  
  my_file <- paste0("D:/Dataset/",input$table,".xlsx")
  }

  sheetNames <- function(){
  sheetNames <- getSheetNames(my_file())
  }


    output$sheets <- renderUI({
    selectInput("sheet","Sheet:",choices = sheetNames())
    })

    output$table <- DT::renderDataTable(DT::datatable({    
    data <- read.xlsx(my_file(),sheet=as.character(input$sheet))
    data
    }))


}

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.

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