r语言 - 如何解决错误" 文件中的错误:无效的"描述"参数?



我写了一个闪亮的代码,它有一个包含以下元素的仪表板

1( 侧边栏布局 2(单击选项卡"视图"时,主面板填充了选项卡集面板 3(单击"表"时,应显示两个选择输入,其中工作表下拉列表依赖于"表"下拉列表。数据集是从 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)

但是在实现上述内容时,我收到错误(附上屏幕截图(

"错误:无效的'描述'参数" "错误:无法将类型'闭包'强制为类型'列表'的向量

请帮助解决问题

您必须用括号调用反应值(file在第 62 行声明的无功值(。但是在基数 R 中有一个file()函数,因此更改它例如 formy_file并用括号调用它,例如:

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

下面的代码工作正常

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

}

最新更新