Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- shinyApp(
- ui = basicPage(
- actionButton("show", "Show modal dialog"),
- verbatimTextOutput("print")
- ),
- server = function(input, output) {
- vals <- reactiveValues(txt = NULL)
- # Create modal
- popupModal <- function(failed = FALSE) {
- modalDialog(
- textInput("txt", "Write something"),
- if (failed)
- div(tags$b("You did not input anything", style = "color: red;")),
- footer = tagList(
- modalButton("Cancel"),
- actionButton("ok", "OK")
- )
- )
- }
- # Show modal when button is clicked.
- observeEvent(input$show, {
- showModal(popupModal())
- })
- observeEvent(input$ok, {
- if (!is.null(input$txt) && nzchar(input$txt)) {
- vals$txt <- input$txt
- removeModal()
- } else {
- showModal(popupModal(failed = TRUE))
- }
- })
- # Print inputted text
- output$print <- renderPrint({
- if (is.null(vals$txt))
- "No data selected"
- else
- vals$txt
- })
- }
- )
Add Comment
Please, Sign In to add comment