Skip to content

Instantly share code, notes, and snippets.

@MayaGans
Created Sep 10, 2020
Embed
What would you like to do?
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