Modules and applications
modules-and-applications.Rmd
This 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 thedatasets
package ("dataset"
) matchingfilter
argument (i.e.,is.data.frame
,is.matrix
) and the table output ("data"
) in the UIThe
inputId
in the UI passes adatasets
object (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-
dataset
module:datasetInput()
displays the objects from thedatasets
package ("dataset"
) matchingfilter
argument (i.e.,is.data.frame
,is.matrix
) and the table output ("data"
) in the UIThe
inputId
in the UI passes adatasets
object (asinput$dataset
, a character string) todatasetServer()
, which fetches and returns the object as a reactive withget()
-
selectVar
module:selectVarInput()
displays the variables (columns) in the returneddatasets
object fromdatasetServer()
(as"var"
) and the rendered output (as"out"
)In
selectVarServer()
, the columns in thedata
returned fromdatasetServer()
is filtered to those columns matching thefilter
argument (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 theselectVar
moduleid
, the second is from theselectInput()
"data"
is from thedataset
moduleid
, the second is from theselectInput()
selectDataVarApp()
-
selectDataVarApp()
nests thedataset
andselectVar
modules inside theselectDataVarUI()
andselectDataVarServer()
functions:-
dataset
module:datasetInput()
displays the objects from thedatasets
package ("dataset"
) matchingfilter
argument (i.e.,is.data.frame
,is.matrix
) and the table output ("data"
) in the UIThe
inputId
in the UI passes adatasets
object (asinput$dataset
, a character string) todatasetServer()
, which fetches and returns the object as a reactive withget()
-
selectVar
module:selectVarInput()
displays the variables (columns) in the returneddatasets
object fromdatasetServer()
(as"var"
) and the rendered output (as"out"
)In
selectVarServer()
, the columns in thedata
returned fromdatasetServer()
is filtered to those columns matching thefilter
argument (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()))