r - 将多个 rshiny 应用程序合二为一
问题描述
我有几个闪亮的应用程序,我想将它们全部组合成一个应用程序。但是,我不想使用该
source()
功能,而是想为每个闪亮的应用程序复制粘贴代码。现在,如果其他人运行此应用程序,则会出现错误。知道如何做到这一点吗?
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
menuItem("first_app", tabName = "first_app"),
menuItem("second_app", tabName = "second_app")
)
),
dashboardBody(
tabItems(
tabItem(tabName = "first_app",
h2(source("sir.shiny.R", local = TRUE)$value)
),
tabItem(tabName = "second_app",
h2(source("seir.shiny.R", local = TRUE)$value)
)
)
)
)
server <- function(input,output,server){}
shinyApp(ui,server)
解决方案
也许您正在寻找这个:在上面定义所有函数ui
(或将它们放入global.R
),并在服务器函数中绘制每个模型。侧边栏允许用户选择感兴趣的模型。见下文。
## Define your own functions above ui or inside global.R
mySEIR <- function(t, y, parms) {
with(as.list(c(y, parms)),{
# Change in Susceptibles
dS <- - beta * S * I
# Change in Exposed
dE <- beta * S * I - sigma * E
# Change in Infecteds
dI <- sigma * E - gamma * I
# Change in Recovereds
dR <- gamma * I
return(list(c(dS, dE, dI, dR)))
})
}
ui <- dashboardPage(
dashboardHeader(title = div("Test SEIR app")),
dashboardSidebar(
sidebarMenu(id="tabs",
menuItem("Home", tabName = "home", icon = icon("home")),
menuItem("SIR", tabName = "first_app"),
menuItem("SEIR", tabName = "second_app")
)
),
dashboardBody(
tabItems(
tabItem(tabName = "first_app", plotOutput("plotSIR")
),
tabItem(tabName = "second_app", plotOutput("plotSEIR")
)
)
)
)
server <- function(input, output, session){
output$plotSIR <- renderPlot({qplot(rnorm(500),fill=I("red"),binwidth=0.2)})
output$plotSEIR <- renderPlot({qplot(rnorm(500),fill=I("blue"),binwidth=0.2)})
}
shinyApp(ui,server)
推荐阅读
- jenkins - 如何找到 Jenkins 插件的后端工件?它存储在 Nexus 中吗?只需要工件的路径
- java - log4j2-slf4j-impl 重复依赖
- ios - 当先前连接的外围设备稍后重新连接(源自外围设备的连接)时,如何获得通知?
- php - 在 html 中访问 mysql 值以通过 jquery 发送到 php 文件
- javascript - 如何获取数组中复选框的值
- c# - 如何通过反射设置作为通用接口的字段的值?
- awk - 如何根据其他数据排除某些数据
- r - tmap facets 没有出现在 R 闪亮中
- html - 如何在 HTML 中使用自定义字体?
- acumatica - 为 PXSelector 提供数据查找