In this minimal example, how can I update the textOutput
only after the confirmation of the modalDialog
buttons for the change png -> svg. (svg-> png requires no confirmation)
The confirmation dialog should be available only for the change png -> svg (and other conditions not shown), not the way back.
As the main input affects several reactive outputs (not shown), it is desirable to use reactiveValues.
library(shiny)
ui = fluidPage(
mainPanel(
radioButtons("selectFormat", "Select Format",c("svg","png") ),
uiOutput("textOut")
)
)
server = function(session, input, output) {
values<-reactiveValues()
output$textOut <- renderUI({
textOutput("selection")
})
observe({
values[["format"]]<-input$selectFormat
})
output$selection <-renderText({
paste(values[["format"]], "is selected" )
})
observeEvent(input$selectFormat, ignoreInit = T, {
if (input$selectFormat=="svg") {
showModal(modalDialog(
title="Warning: When changing to '.svg' with condition X, Rstudio will crash",
footer = tagList(actionButton("confirmSvg", "Select .svg anyway"),
actionButton("confirmPng", "stay with .png as suggested")
)
))
}
})
observeEvent(input$confirmSvg, {
updateRadioButtons(session,inputId = "selectFormat", selected="svg")
removeModal()
})
observeEvent(input$confirmPng, {
updateRadioButtons(session,inputId = "selectFormat", selected="png")
removeModal()
})
}
# Run the application
shinyApp(ui = ui, server = server)