Skip to content

Instantly share code, notes, and snippets.

@boeinguy2
Created August 3, 2017 15:27
Show Gist options
  • Save boeinguy2/7ed214704db024fc7137d0244fa41668 to your computer and use it in GitHub Desktop.
Save boeinguy2/7ed214704db024fc7137d0244fa41668 to your computer and use it in GitHub Desktop.
Example of passing values from module to module
# ------------------------------------ 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