如何让ShinyApp在部署到Web上时使用环境变量? [英] How can I make ShinyApp to use environmental variables when deployed on the web?
本文介绍了如何让ShinyApp在部署到Web上时使用环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
几个小时以来,我一直在挣扎。我的Shiny App
应该显示我的R环境中的一些变量。它工作得很好,但是当我将它部署到Web上时,我收到如下错误:
Error: object 'df1' not found
如何添加df1
和其他数据框,以便在部署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"))
)
推荐答案
终于解决了!!基本上,我应该在UI.R
文件的顶部加载我的工作区。这边:
attach("myWorkspace.RData")
这篇关于如何让ShinyApp在部署到Web上时使用环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文