title: "Shiny Module Learning" author: "Brian S Yandell" date: "May 19, 2016" output: html_document
This project is about learning how to use Shiny modules. I developed these as my modules were crashing, and I wanted to break down into simple steps. See links below for official resources.
The folder has several R scripts. Latest material is in the oldfaithful folder. See also Conference Material on Modules. These were adapted from and inspired by Garrett's talk. Each file is a complete shiny app that can be run.
simple.R
simple Shiny script using sliderInput() and textOutput()module.R
simple.R modified to have key components in Shiny modulenested.R
example nesting two modules*_renderUI.R
examples using renderUI() in server and uiOutput() in ui *_observeEvent.R
examples using observeEvent() for actionButton()*_observe.R
examples using observe() for checkboxInput()*_renderUI_*.R
examples using renderUI and observe() or observeEvent()Key things to notice about namespace use for modules:
sliderTextUI("module")
# in ui functioncallModule(sliderText, "module", ...)
# in server functionsession
as third argumentns <- NS(id)
# to create namespace ID functiontagList(
# tag list to wrap UI entriessliderInput(ns("slider"), ...)
# to use namespace ID)
# ends tag listns <- server$ns
# to access namespace ID functionoutput$set_slider <- renderUI({
sliderInput(ns("slider"), ...)
# to use namespace Id})
update*Input
updateSliderInput(server, "slider", ...)
observe()
and observeEvent()
conditionalPanel
does not work as expected with modulescondition
argument is interpreted by javascriptinput
elements for a module namespace require care with JSAdd the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.