Skip to content

byandell/shiny_module

Repository files navigation

title author date output
Shiny Module Learning
Brian S Yandell
May 19, 2016
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 module
  • nested.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:

  • module UI and server must use same id
    • sliderTextUI("module") # in ui function
    • callModule(sliderText, "module", ...) # in server function
  • module server needs session as third argument
  • return argument from module server (if any) must be reactive()
  • module UI needs two nameserver components
    • ns <- NS(id) # to create namespace ID function
    • tagList( # tag list to wrap UI entries
    • sliderInput(ns("slider"), ...) # to use namespace ID
    • ) # ends tag list
  • module server has no special arrangements except in use of renderUI()
    • ns <- server$ns # to access namespace ID function
    • output$set_slider <- renderUI({
    • sliderInput(ns("slider"), ...) # to use namespace Id
    • })
  • module server has no special arrangements for update*Input
    • updateSliderInput(server, "slider", ...)
    • used in observe() and observeEvent()
  • conditionalPanel does not work as expected with modules

About

Learning about Shiny Modules

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages