【问题标题】:Split big shinydashboard app into pieces将大型闪亮仪表板应用程序拆分为多个部分
【发布时间】:2015-08-14 03:21:13
【问题描述】:

我对@9​​87654322@ 和shinydashboard 很陌生。我的第一个应用程序已经增长到一个大小,我想将它重构为多个片段,如http://rstudio.github.io/shinydashboard/structure.html 提示的那样:

dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody()
)

这应该是一个相当简单的任务。但是,我找不到任何关于如何将我的应用程序拆分为多个文件的示例,并且我不确定执行此操作的最佳方法是什么。

到目前为止我无法让它工作:我尝试在每个部分中调用source("myBody.R")

【问题讨论】:

  • 您尝试做的事情是有道理的,因此错误必须在细节中。请分享一个具体的代码示例。

标签: r file shiny shinydashboard


【解决方案1】:

您可以将一些 UI 代码放在不同的文件中,然后使用

将其包含在您的主 UI 中
source("file.R", local=TRUE)$value

你可以在这篇闪亮的文章http://shiny.rstudio.com/articles/scoping.html看到更多细节

【讨论】:

    【解决方案2】:
    1. 看看@Shape 在https://stackoverflow.com/a/33584292/4606130 中的策略。

    server.R:

        library(shiny)
        source('sub_server_functions.R')
    
        function(input, output, session) {
            subServerFunction1(input, output, session)
            subServerFunction2(input, output, session)
            subServerFunction3(input, output, session) 
        }
    

    其他想法是:

    1. 将您的数据调用和常量放在一个 global.R 中,您的 ui 和 server.R 文件都可以共享该文件。看http://shiny.rstudio.com/articles/scoping.html

    2. 看看新的模块方法到 Shiny。我仍在处理这个问题,但看起来很有希望合理化。见http://shiny.rstudio.com/articles/modules.html

    在此之后,flex 仪表板.Rmd 文件的示例看起来很薄!

    ---
    title: "screenR"
    output: flexdashboard::flex_dashboard
    runtime: shiny
    ---
    
    ```{r}
    # include the module
    source("screenrdata.R")
    ```
    
    Charts
    ======
    
    ### Screening Scatter
    
    ```{r}
    
    # call the module
    xyUI("id1")
    callModule(screenchart, "id1")
    ```
    

    【讨论】:

      猜你喜欢
      • 2015-10-13
      • 1970-01-01
      • 2018-08-31
      • 1970-01-01
      • 1970-01-01
      • 2019-03-19
      • 2018-04-28
      • 1970-01-01
      • 2015-04-22
      相关资源
      最近更新 更多