R语言 如何让ShinyApp在部署到Web上时使用环境变量?

r3i60tvu  于 2023-01-15  发布在  其他
关注(0)|答案(2)|浏览(165)

几个小时以来我一直在挣扎。我的Shiny App应该显示一些我在R环境中的变量。它工作正常,但当我把它部署到Web时,我得到了如下错误:

Error: object 'df1' not found

如何添加df1和其他 Dataframe ,以便在部署Shiny App时将其打包为Shiny App的一部分?
下面是我的示例代码:
server.R

library(shiny)

shinyServer(function(input,output){
output$datasets <- renderTable({
switch(input$choice,

         "1" = as.data.frame(df1)          
         "2" = as.data.frame(df2) })
  }))

UI.R

shinyUI(
fluidPage(theme = "bootstrap.css",

sidebarPanel(        
  conditionalPanel(
    condition = "input.theTab == 'datasets' ",
    h3('Display Sample Data'),    
    selectInput("choice", "Selection", choices = c("Group1"=1,"Group2"=2)),

  )),

mainPanel(
  tabsetPanel(
    tabPanel( "datasets", tableOutput("datasets"), value = 'datasets'),
    id = "theTab"))
)
bxpogfeg

bxpogfeg1#

在最新的版本中,你可以在一个 global.R 文件中包含变量,这些变量可以在用户界面和服务器上使用。
http://shiny.rstudio.com/articles/scoping.html

guykilcj

guykilcj2#

终于找到了解决方案!!基本上我应该在UI.R文件的顶部加载我的工作空间。

attach("myWorkspace.RData")

相关问题