Split a large shinydashboard application into parts

I am new to shiny

and shinydashboard

. My first app has grown to such a size that I would like to refactor it into chunks as shown by http://rstudio.github.io/shinydashboard/structure.html here:

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

      

This should be a fairly simple task. However, I couldn't find examples of how to split my application into multiple files, and I'm not sure if this is the best way to do it.

I couldn't get it to work so far: I've tried calling source("myBody.R")

inside each part.

+1


source to share


2 answers


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:



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

  2. Take a look at the new approach to the module on Shiny. I'm still handling it, but it seems to promise to rationalize. See http://shiny.rstudio.com/articles/modules.html

The sample .Rmd

flex control panel 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")
```

      

+1


source


You can have some UI code in another file and then include it in your main interface with

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

      



You can see more details on this brilliant article http://shiny.rstudio.com/articles/scoping.html

+3


source







All Articles