Create a popup dialog box interactive

前端 未结 3 1196
情书的邮戳
情书的邮戳 2020-12-25 10:35

I was wondering if it is possible to create a popup dialog box interactive by using shiny (and shinyBS).

For example, I have a string and I want to change it and bef

3条回答
  •  难免孤独
    2020-12-25 10:45

    You can do something like this using conditionalPanel, I would further suggest adding a button to ask for confirmation oppose to instant update.

    rm(list = ls())
    library(shiny)
    library(shinyBS)
    
    name <- "myname"
    
    ui = fluidPage(
      uiOutput("curName"),
      br(),
      actionButton("BUTnew", "Change"),
      bsModal("modalnew", "Change name", "BUTnew", size = "small",
              textOutput("textnew"),
              radioButtons("change_name", "", choices = list("Yes" = 1, "No" = 2, "I dont know" = 3),selected = 2),
              conditionalPanel(condition = "input.change_name == '1'",textInput("new_name", "Enter New Name:", ""))    
        )
      )
    )
    
    server = function(input, output, session) {
    
      output$curName <- renderUI({textInput("my_name", "Current name: ", name)})
    
      observeEvent(input$BUTnew, {
        output$textnew <- renderText({paste0("Do you want to change the name?")})
      })
    
      observe({
        input$BUTnew
        if(input$change_name == '1'){
          if(input$new_name != ""){
            output$curName <- renderUI({textInput("my_name", "Current name: ", input$new_name)})
          }
          else{
            output$curName <- renderUI({textInput("my_name", "Current name: ", name)})
          }
        }
      })
    }
    
    runApp(list(ui = ui, server = server))
    

提交回复
热议问题