Guest User

Untitled

a guest
Feb 23rd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. library(shiny)
  2.  
  3. shinyApp(
  4. ui = basicPage(
  5. actionButton("show", "Show modal dialog"),
  6. verbatimTextOutput("print")
  7. ),
  8.  
  9. server = function(input, output) {
  10.  
  11. vals <- reactiveValues(txt = NULL)
  12.  
  13. # Create modal
  14. popupModal <- function(failed = FALSE) {
  15. modalDialog(
  16. textInput("txt", "Write something"),
  17. if (failed)
  18. div(tags$b("You did not input anything", style = "color: red;")),
  19.  
  20. footer = tagList(
  21. modalButton("Cancel"),
  22. actionButton("ok", "OK")
  23. )
  24. )
  25. }
  26.  
  27. # Show modal when button is clicked.
  28. observeEvent(input$show, {
  29. showModal(popupModal())
  30. })
  31.  
  32. observeEvent(input$ok, {
  33.  
  34. if (!is.null(input$txt) && nzchar(input$txt)) {
  35. vals$txt <- input$txt
  36. removeModal()
  37. } else {
  38. showModal(popupModal(failed = TRUE))
  39. }
  40. })
  41.  
  42. # Print inputted text
  43. output$print <- renderPrint({
  44. if (is.null(vals$txt))
  45. "No data selected"
  46. else
  47. vals$txt
  48. })
  49. }
  50. )
Add Comment
Please, Sign In to add comment