Hi, is there a way to have multiple modalDialog
show up? At the moment, only one will.
The real-life use case is for users uploading data via a template with the popups showing if there are data issues. This is a simplified example though without any data uploads. The popups will show if 'C' is selected, with a table also showing (which would represent the data issue). If 'C' is selected in both though, only the second table shows.
I had a look at this, and I don't know how it might work with tables. only last modal shows when multiple modals are triggered by the same event · Issue #3835 · rstudio/shiny
Any ideas?
library(shiny)
library(DT)
shinyApp(
ui = basicPage(
selectInput("a",
label = "a",
choices = c("A", "B", "C"),
selected = "A"),
selectInput("b",
label = "b",
choices = c("A", "B", "C"),
selected = "B"),
actionButton("click",
label = "click")
), # end ui
server = function(input, output, session) {
# observe the click - show modal depending on what is selected -----------------
observeEvent(input$click,{
if(input$a == "C"){
showModal(
modalDialog(
p("test1"),
dataTableOutput("aa")
)
)
}
if(input$b == "C"){
showModal(
modalDialog(
p("test2"),
dataTableOutput("bb")
)
)
}
}, ignoreInit = TRUE)
# tables ------------------------------------------------------------------------
output$aa <- renderDataTable(datatable(iris))
output$bb <- renderDataTable(datatable(mtcars))
} # end server
)
And an attempt that doesn't work:
library(shiny)
library(DT)
shinyApp(
ui = basicPage(
selectInput("a",
label = "a",
choices = c("A", "B", "C"),
selected = "A"),
selectInput("b",
label = "b",
choices = c("A", "B", "C"),
selected = "B"),
actionButton("click",
label = "click")
), # end ui
server = function(input, output, session) {
# store values
rv <- reactiveValues()
rv$warning_list <- list()
# observe the click - show modal depending on what is selected -----------------
observeEvent(input$click,{
if(input$a == "C"){
rv$warning_list <- list(rv$warning_list, list("test1", iris))
}
if(input$b == "C"){
rv$warning_list <- list(rv$warning_list, list("test2", mtcars))
}
if(length(rv$warning_list) > 0){
showModal(
modalDialog(
p(rv$warning_list[[1]][[1]]),
dataTableOutput(
renderDataTable(
datatable(rv$warning_list[[1]][[2]])
)
)
)
)
}
}, ignoreInit = TRUE)
} # end server
)