Skip to content

Instantly share code, notes, and snippets.

@MayaGans
Created September 10, 2020 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MayaGans/f82ad8dbe7480d844d2a2b8c1e5afd74 to your computer and use it in GitHub Desktop.
Save MayaGans/f82ad8dbe7480d844d2a2b8c1e5afd74 to your computer and use it in GitHub Desktop.
library(shiny)
source("parent_module.R")
source("child_module.R")
ui <- fluidPage(
parent_mod_ui("parent")
)
server <- function(input, output) {
callModule(parent_mod_srv, "parent")
}
shinyApp(ui = ui, server = server)
child_mod_ui <- function(id) {
ns <- NS(id)
tagList(
sliderInput(ns("the_slider"), "SLIDE", min = 0, max = 10, value = 3)
)
}
child_mod_srv <- function(input, output, session) {
ns <- session$sn
observeEvent(input$the_slider, {
if (input$the_slider > 5) shinyjs::disable("parent-toggle_disable")
})
}
parent_mod_ui <- function(id) {
ns <- NS(id)
actionButton(ns("click_me"), "CLICK ME")
}
parent_mod_srv <- function(input, output, session) {
ns <- session$ns
observeEvent(input$click_me, {
showModal(
modalDialog(
title = "This is a modal",
footer = actionButton(ns("toggle_disable"), "CLOSE MODAL"),
child_mod_ui(ns("child"))
)
)
})
observeEvent(input$click_me, {
callModule(child_mod_srv, "child")
})
observeEvent(input$toggle_disable, {
removeModal()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment