I'm designing an app that will have multiple tabs that all have basic ui features on the side, but hid various advanced UI options in a pop-up modal button. Some of these options are responsive to the dataset, for example choosing which rows to use.
I want to use modules to design the app, but am running into trouble getting reactive UI elements into the modals.
I think modalUI1 is getting the right namespace, but when I call uiOutput on the reactive ui element made by settingsServer1 it doesn't show up.
The closest slack post I found did something similar, but the modal they had static UI.
It can be found Here
Below is the reproducible code:
# Basic View Functions ----------------------------------------------------
# These modules setup the basic view for each analysis
simpleui <- function(id){
ns <- NS(id)
selectData <- selectInput(ns("d"), "Dataset:",
c("iris",
"mtcars",
"iris3"))
outputRows <- verbatimTextOutput(ns("df"))
settingsButton<-
actionButton(
ns("settings"),
"Settings")
tabPanel(id,
tagList(
p(),
selectData,
p(),
outputRows,
p(),
settingsButton
)
)
}
view1 <- function(input, output, session) {
reactiveDf <- reactive({
switch(input$d,
"iris" = iris,
"mtcars" = mtcars,
"iris3"= iris3)
})
output$df <- renderText({nrow(reactiveDf())})
callModule(settingsServer1, "settings", reactiveDf)
observeEvent(input$settings, {
showModal(settngsModal(session$ns))
})
settngsModal <- function(ns) {
# ns <- NS(id) ### This is inner UI so passed namespace from outer
modalDialog(
modalUI1("settings"), ### Call innerModalUI.
# withTags({ # UI elements for the modal go in here
# fluidRow(
# column(4, "Inputs","Sectionnormal",uiOutput("nrowSlide")),
# column(4, "Inputs","Sectionnormal",uiOutput(ns("nrowSlide")))
# )}
,
title = "Settings",
footer = modalButton("Dismiss"),
size = "l",
easyClose = FALSE,
fade = TRUE)
}
}
# Advanced settings hidden in modal ---------------------------------------
# These functions should hide the advanced UI settings in a Modal.
modalUI1 <- function(ns) {
### Several UI elements 1 of which chooses which first N Rows.
### The slider is reactive
# reactiveSlider <- uiOutput("nrowSlide")
withTags({ # UI elements for the modal go in here
fluidRow(
# print(ns("nrowSlide")),
# print(input),
column(4, "---------",uiOutput(("nrowSlide")), "---------")
)
})
}
settingsServer1 <- function(input, output, session, reactiveDf){
output$nrowSlide <- renderUI({
sliderInput("obs", "Number of observations:",
min = 1, max = nrow(reactiveDf()), value = 1)
})
}
# Basic Setup -------------------------------------------------------------
ui <- shinyUI(navbarPage("My Application",
simpleui("v1"),
simpleui("v2")
))
server <- function(input, output, session) {
callModule(view1, "v1")
callModule(view1, "v2")
### Also look for event to create a modal.
### This modal will have reactive items.
}
shinyApp(ui, server)