【发布时间】:2015-06-04 04:58:16
【问题描述】:
我一直在开发一个 Shiny 应用程序,其中 ui.R 脚本变得很长并且变得难以管理。我想将代码分成不同的部分,然后在ui 中调用它们。我想这对于嵌套和复杂的不同面板特别有用。
有没有办法做到这一点?
示例ui.R 脚本:
shinyUI(pageWithSidebar(
headerPanel('Iris k-means clustering'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(iris)),
selectInput('ycol', 'Y Variable', names(iris),
selected=names(iris)[[2]]),
numericInput('clusters', 'Cluster count', 3,
min = 1, max = 9)
),
mainPanel(
plotOutput('plot1')
)
))
如果我能把它改成下面的就好了(我用伪代码写的):
shinyUI(pageWithSidebar(
headerPanel('Iris k-means clustering'),
source("call_sidebarPanel.R"),
mainPanel(
plotOutput('plot1')
)
))
call_sidebarPanel.R
sidebarPanel(
selectInput('xcol', 'X Variable', names(iris)),
selectInput('ycol', 'Y Variable', names(iris),
selected=names(iris)[[2]]),
numericInput('clusters', 'Cluster count', 3,
min = 1, max = 9)
)
【问题讨论】: