如何解决错误“文件错误:无效的'description'参数?

时间:2019-08-16 16:54:17

标签: r user-interface shiny rstudio shinydashboard

我编写了一个Shiny代码,其中包含具有以下元素的仪表板

1)侧栏布局 2)单击“查看”选项卡时,主面板将填充为“标签集”面板 3)在单击“表格”时,应显示两个selectInput,其中工作表下拉列表取决于表格下拉列表。从xlsx文件读取数据集

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)

但是在执行上述操作时,出现了错误(附有屏幕截图)

“错误:无效的'描述'参数” “错误:无法将类型'closure'强制转换为类型'list'的向量

请帮助解决问题

2 个答案:

答案 0 :(得分:1)

您必须用括号来调用电抗值(第62行中声明的file电抗值)。但是在基数R中有一个file()函数,因此请更改此值,例如my_file并用括号括起来,例如:

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

答案 1 :(得分:0)

下面的代码可以正常工作

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
    }))


}