There are several diagrams in my application, and I would like to draw them in a sperate script in order to have a cleaner one server.R, which then only contains calls bind_shiny.
Also, since I would like to rework some of the main blocks of my diagrams, I would like to split the script into drawing diagrams in smaller parts of the code.
I know correctly, I have a charts.R file :
chart1 <- reactive({
cars %>%
ggvis(~speed)
})
chart2 <- reactive({
chart1 %>% layer_bars()
})
Reactivity is not needed, of course, but it will be in my original application.
Then I would like to name the diagram on server.R as follows:
library(shiny)
library(ggvis)
source("charts.R")
shinyServer(function(input, output) {
chart2 %>%
bind_shiny("test1", "test1_ui")
})
ui.R
library(shiny)
library(ggvis)
shinyUI(fluidPage(
fluidRow(titlePanel("My app")),
fluidRow(
column(12,
tags$h1("hello"),
ggvisOutput('test1')
)
)
)
)
, charts.R, , , , . , -
> a <- cars %>%
+ ggvis(~speed)
> a
Guessing layer_histograms()
Guessing width = 0.5 # range / 42
> a %>% layer_bars()
- , R, Shiny?