拆分大shinydashboard应用程序成片 [英] Split big shinydashboard app into pieces

查看:133
本文介绍了拆分大shinydashboard应用程序成片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

闪亮的 shinydashboard 我很新。我的第一个应用程序已经发展到一个规模,我想重构成片断,如暗示 http:// rstudio.github.io/shinydashboard/structure.html

$ $ $ $ $ c $ d> dashboardPage(
dashboardHeader() ,
dashboardSidebar(),
dashboardBody()

这应该是一个相当简单的任务。然而,我找不到任何关于如何将我的应用程序分割成多个文件的例子,我不知道最好的办法是什么。



我不能让它工作到目前为止:我试着在每个部分调用 source(myBody.R)

解决方案


  1. https:// stackoverflow .com / a / 33584292/4606130

server.R:

  library(shiny)
source('sub_server_functions.R')

函数(输入,输出,session){
subServerFunction1(输入,输出,会话)
subServerFunction2(输入,输出,会话)
subServerFunction3(输入,输出,会话)

其他想法如下:


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


  2. 查看Shiny的新模块方法。我仍然正在处理这个,但看起来很有希望合理化。请参阅 http://shiny.rstudio.com/articles/modules.html

一个Flex仪表盘 .Rmd 文件的例子看起来很薄在这之后!

  --- 
title:screenR
输出:flexdashboard :: flex_dashboard
runtime:shiny
---
$ b $```{r}
#包含模块
source(screenrdata.R)
```

图表
======

###筛选散点图

```{r}
$ b $调用模块
xyUI(id1)
callModule(screenchart,id1)
```


I'm quite new to shiny and shinydashboard. My first application has grown to a size that I would like to refactor it into pieces as hinted http://rstudio.github.io/shinydashboard/structure.html here:

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

It should be a fairly simple task. However, I could not find any examples on how to split my app into multiple files, and I am not sure what is the best way to do this.

I could not get it to work so far: I tried calling source("myBody.R") within each part.

解决方案

  1. Take a look at @Shape's strategy in 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) 
    }

Other ideas are:

  1. Put your data calls and constants in a global.R which can be shared by both your ui and server.R file. Look at http://shiny.rstudio.com/articles/scoping.html

  2. Look at the new Module approach to Shiny. I am still getting to grips with this but looks promising to rationalise. See http://shiny.rstudio.com/articles/modules.html

An example of a flex dashboard .Rmd file looks pretty thin after this!

---
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")
```

这篇关于拆分大shinydashboard应用程序成片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆