Last active
November 26, 2016 15:34
-
-
Save martinv13/b599b66cab1023963fc81559ead70a3e to your computer and use it in GitHub Desktop.
A simple Shiny module with input and output values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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