Modules and applications
modules-and-applications.RmdThis vignette covers the standalone shiny apps in the
mstsap package.
Apps from Mastering Shiny
Three of the applications in the mstsap package come
from the Modules section
of Mastering Shiny:
datasetApp()
-
datasetApp()contains thedatasetInput()anddatasetServer()module functionsdatasetInput()displays the objects from thedatasetspackage ("dataset") matchingfilterargument (i.e.,is.data.frame,is.matrix) and the table output ("data") in the UIThe
inputIdin the UI passes adatasetsobject (asinput$dataset, a character string) todatasetServer(), which fetches and returns the object as a reactive viaget()
█─datasetApp
├─filter = NULL
└─█─shinyApp
├─ui = █─fluidPage
│ ├─█─datasetInput
│ │ ├─id = "dataset"
│ │ ├─filter = is.data.frame
│ │ └─█─selectInput
│ │ └─inputId = "dataset"
│ └─█─tableOutput
│ └─"data"
└─server = █─function(input, output, session)
└─█─data <- datasetServer(id = "dataset")
└─output$data <- renderTable(head(data()))
selectVarApp()
-
selectVarApp()contains thedatasetInput()/Server()andselectVarInput()/Server()modules-
datasetmodule:datasetInput()displays the objects from thedatasetspackage ("dataset") matchingfilterargument (i.e.,is.data.frame,is.matrix) and the table output ("data") in the UIThe
inputIdin the UI passes adatasetsobject (asinput$dataset, a character string) todatasetServer(), which fetches and returns the object as a reactive withget()
-
selectVarmodule:selectVarInput()displays the variables (columns) in the returneddatasetsobject fromdatasetServer()(as"var") and the rendered output (as"out")In
selectVarServer(), the columns in thedatareturned fromdatasetServer()is filtered to those columns matching thefilterargument (i.e.,is.numeric), and the selected"var"is displayed in"out"
-
█─selectVarApp
└─█─shinyApp
├─ui = █─fluidPage
│ ├─█─datasetInput
│ │ ├─id = "data"
│ │ ├─filter = is.data.frame
│ │ └─█─selectInput
│ │ └─inputId = "dataset"
│ ├─█─selectVarInput
│ │ ├─id = "var"
│ │ └─█─selectInput
│ │ └─inputId = "var"
│ └─█─tableOutput
│ └─"out"
└─server = █─function(input, output, session)
└─█─data <- datasetServer("data")
█─var <- selectVarServer("var", data, filter = is.numeric)
└─output$out <- renderTable(head(var()))
Reactive values
The output from reactiveValuesToList() for both modules
are displayed in the dev version of the application:
$`var-var`
[1] "Ozone"
$`data-dataset`
[1] "airquality"
The first
"var"is from theselectVarmoduleid, the second is from theselectInput()"data"is from thedatasetmoduleid, the second is from theselectInput()
selectDataVarApp()
-
selectDataVarApp()nests thedatasetandselectVarmodules inside theselectDataVarUI()andselectDataVarServer()functions:-
datasetmodule:datasetInput()displays the objects from thedatasetspackage ("dataset") matchingfilterargument (i.e.,is.data.frame,is.matrix) and the table output ("data") in the UIThe
inputIdin the UI passes adatasetsobject (asinput$dataset, a character string) todatasetServer(), which fetches and returns the object as a reactive withget()
-
selectVarmodule:selectVarInput()displays the variables (columns) in the returneddatasetsobject fromdatasetServer()(as"var") and the rendered output (as"out")In
selectVarServer(), the columns in thedatareturned fromdatasetServer()is filtered to those columns matching thefilterargument (i.e.,is.numeric), and the selected"var"is displayed in"out"
-
█─selectDataVarApp
└─█─shinyApp
├─ui = █─fluidPage
│ └─█─sidebarLayout
│ ├─█─sidebarPanel
│ │ └─█─selectDataVarUI
│ │ ├─"var"
│ │ ├─█─datasetInput
│ │ │ ├─█─NS
│ │ │ │ ├─id
│ │ │ │ └─"data"
│ │ │ └─filter = is.data.frame
│ │ └─█─selectVarInput
│ │ └─█─NS
│ │ ├─id
│ │ └─"var"
│ └─█─mainPanel
│ └─█─verbatimTextOutput
│ └─"out"
└─server = █─function(input, output, session)
├─█─var <- selectDataVarServer(id = "var", filter = is.numeric)
│ ├─data <- datasetServer(id = "data")
│ ├─var <- selectVarServer(id = "var", data, filter = filter)
│ └─var
└─output$out <- renderPrint(head(var()))