【问题标题】:Shiny - Call panel from external codeShiny - 从外部代码调用面板
【发布时间】: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)
  )

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    是的,这是可能的,我也在所有重要的应用程序中都这样做。诀窍是使用

    source("file.R", local = TRUE)$value
    

    This shiny article 有这方面的一些信息。

    【讨论】:

    • 优秀!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多