[英]How to resolve error " Error in file : invalid 'description' argument?
I have written a Shiny code that has a dashboard with the following elements 我编写了一个Shiny代码,其中包含一个包含以下元素的仪表板
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. 1)侧栏布局2)单击选项卡“视图”时,将在主面板中填充选项卡集面板3)在单击“表”时,应显示两个selectInput,其中工作表下拉菜单取决于表下拉菜单。 The Datasets are read from xlsx files 从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)
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' “错误:无效的”描述“参数”“错误:无法将类型” closure“强制转换为类型” list“的向量
Please help resolving the issue 请协助解决问题
You have to call reactive values with parentheses ( file
reactive value declared in line 62). 您必须使用括号来调用无功值(第62行中声明的file
无功值)。 But there is a file()
function in base R, so change this eg for my_file
and call it with parentheses, eg: 但是在基数R中有一个file()
函数,因此请更改此参数(例如, my_file
并用括号将其调用,例如:
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
}))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.