#Dynamically adding modules
library(shiny)
#slider module ------------------------
sliderUI <- function(id) {
  ns <- NS(id)
  sliderInput(ns("bins"), "Number of Bins:", min = 1, max = 5, value = 3)
}
slider <- function(input, output, session) {}
#shiny app ------------------------
ui <- fixedPage(
  fixedRow(
    column(width = 4, wellPanel(
      h4("Slider Module"),
      sliderUI("slider"),
      actionButton("addSliderModule", "Add Slider Module"))
    ),
    column(width = 4, wellPanel(
      h4("Dynamic Loading Modules"),
      p("Clicking on the 'Add' button on the left should add the module here. You should be able to duplicate that slider module as many times as the button is clicked"),
      hr())
    )
  )
)
server <- function(input, output, session) {
  observeEvent(input$addSliderModule, {
    #what goes here
  })
}
shinyApp(ui, server)#Dynamically adding modules
    library(shiny)
    
    #slider module ------------------------
    sliderUI <- function(id) {
      ns <- NS(id)
      tagList(
        sliderInput(ns("bins"), "Number of Bins:", min = 1, max = 5, value = 3),
        textOutput(ns("textBins"))  
      )
    }
    
    slider <- function(input, output, session) {
      output$textBins <- renderText({
        input$bins
      })
    }
    
    
    #shiny app ------------------------
    ui <- fixedPage(
      fixedRow(
        column(width = 4, wellPanel(
          h4("Slider Module"),
          sliderUI("originalSlider"),
          actionButton("addSliderModule", "Add Slider Module"))
        ),
        column(width = 4, wellPanel(
          h4("Dynamic Loading Modules"),
         
 p("Clicking on the 'Add' button on the left should add the module here.
 You should be able to duplicate that slider module as many times as the
 button is clicked"),
          hr(),
          uiOutput("addModule"))
        )
      )
    )
    
    server <- function(input, output, session) {
      #server code for the original module
      callModule(slider, "originalSlider")
      
      #Here we add the UI and callModule of the duplicate module
      observeEvent(input$addSliderModule, {
        duplicateSliderid <- paste0("duplicateSlider", input$addSliderModule)
        
        output$addModule <- renderUI({
          sliderUI(duplicateSliderid)
        })
        callModule(slider, duplicateSliderid)
        
      })
    }
    
    shinyApp(ui, server)--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/287191a7-e6d5-43e1-bf24-56c8b9a6d75a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.