值 [[3L]] 错误(cond):找不到对象 'opcije'

Error in value [[3L]] (cond): Object 'opcije' not found

下面的代码在离线会话中以我想要的方式工作。

opcije <- ls()[sapply(ls(), function(x) class(get(x))) == 'data.frame']

ui <- fluidPage(
    selectInput("language", "Zadatak 3 - No-", choices =  opcije), 
    textOutput("tekstZadatka"),
    tableOutput("tabela")
)
server <- function(input, output, session) {
    
output$tekstZadatka <- renderText({'some text whatever'})

    output$tabela <- renderTable({
        dataset <<- get(input$language)
        dataset
    })  
}

shinyApp(ui, server)

变量 opcije 是全局定义的字符向量,用于从 glob 环境中获取 n 个数据帧之一。但是,将此代码部署到服务器后,我发现未找到对象 'opcije':

我将非常感谢有关如何克服此问题的任何建议。 这也是来自仪表板的日志。

已解决。我遗漏的部分是数据必须在服务器函数内加载,而不是在 app.R 内。现在部署后,代码工作正常。

server <- function(input, output, session) {
    
output$tekstZadatka <- renderText({'some text whatever'})

    for (n in 1:5){
        assign(paste("zadatak_", n, sep =''), read.csv(paste("Zadaci", paste("zadatak_", 
               n, ".csv", sep =''), sep ='/')))
    }
    
    output$tabela <- renderTable({
        dataset <- get(input$language)
        dataset
    })  
}