Created
August 3, 2017 15:27
-
-
Save boeinguy2/7ed214704db024fc7137d0244fa41668 to your computer and use it in GitHub Desktop.
Example of passing values from module to module
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
# ------------------------------------ MODULE ---------------------------------- | |
# ------------------------------------------------------------------------------ | |
# Char module UI | |
CatOptionInput <- function(id) { | |
ns <- NS(id) | |
tagList( | |
br(), | |
br(), | |
radioButtons(ns("processF"), | |
"Class of Processes:", | |
c("Table" = "Table", | |
"Chair" = "Chair") | |
) | |
) | |
} | |
# module server for PNC Text Input | |
CatOption <- function(input, output, session) { | |
return( | |
reactive(input$processF) | |
) | |
} | |
CharOptionInput <- function(id) { | |
ns <- NS(id) | |
tagList( | |
br(), | |
br(), | |
selectInput(ns("charact"), | |
label = "Characteristics:", | |
choices = unlist(c("")) | |
) | |
) | |
} | |
# Char module server for PNC Text Input | |
CharOption <- function(input, output, session, PODData, category) { | |
cnamelist <- function(PODData,cat) { | |
PODData[PODData$Feature == cat,]$Characteristic | |
} | |
observe({updateSelectInput(session, "charact", choices = cnamelist(PODData,category()))}) | |
return(list( | |
Charact = reactive({input$charact}) | |
)) | |
} | |
# ----------------------------------- MAIN APP --------------------------------- | |
# ------------------------------------------------------------------------------ | |
library(shiny) | |
Historical <- tibble::tibble( | |
Feature = c("Table", "Table", "Chair", "Chair"), | |
Characteristic = c( | |
"Length 1", | |
"Width 2", | |
"Height 3", | |
"Depth 4" | |
) | |
) | |
ui <- fluidPage( | |
sidebarLayout( | |
sidebarPanel(), | |
mainPanel(CatOptionInput("cat1"), | |
CharOptionInput("char1")) | |
) | |
) | |
server <- function(input, output, session) { | |
print(Historical) | |
# type <- "Table" | |
results2 <- callModule(CatOption,"Cat1") | |
results <- callModule(CharOption, "char1", PODData = Historical, category = results2) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment