Skip to content

Instantly share code, notes, and snippets.

@martinv13
Last active November 26, 2016 15:34
Show Gist options
  • Save martinv13/b599b66cab1023963fc81559ead70a3e to your computer and use it in GitHub Desktop.
Save martinv13/b599b66cab1023963fc81559ead70a3e to your computer and use it in GitHub Desktop.
A simple Shiny module with input and output values
library(shiny)
testModuleInput <- function (id) {
ns <- NS(id)
uiOutput(ns("inputUI"))
}
testModule <- function (input, output, session, label) {
ns <- session$ns
value <- reactiveValues(value="")
output$inputUI <- renderUI({
textInput(ns("text"), label(), value$value)
})
observe({
value$value <- input$text
})
return( reactive(value$value) )
}
appUI <- fluidPage(
textInput("moduleLabel", "Module label", "default label"),
testModuleInput("testModule1"),
textOutput("testOutput")
)
appServer <- function (input, output) {
module1 <- callModule(testModule, "testModule1", reactive(input$moduleLabel))
output$testOutput <- renderText(module1())
}
shinyApp(appUI, appServer)
library(shiny)
testModuleUI <- function (id) {
ns <- NS(id)
uiOutput(ns("inputUI"))
}
testModule <- function (input, output, session, label) {
ns <- session$ns
value <- reactiveValues(value="")
output$inputUI <- renderUI({
textInput(ns("text"), label(), value$value)
})
observe({
value$value <- input$text
})
return( reactive(value$value) )
}
appUI <- fluidPage(
textInput("moduleLabel", "Module label", "default label"),
moduleOutput("testModule1"),
textOutput("testOutput")
)
appServer <- function (input, output) {
output$testModule1 <- callOrRenderModule(testModule, reactive(input$moduleLabel))
output$testOutput <- renderText(reactive(input$testModule1))
}
shinyApp(appUI, appServer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment