闪亮的 bsModal 关闭按钮

shiny bsModal close button

我有一个名为 Ok 的 actionButton。当用户单击此按钮时,它将从文本输入框中获取输入并显示带有一些消息的 bsModal 消息对话框 window。

这是代码:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(

    textInput("text", "Enter Id:"),
    box(width = 1, background  = 'purple'),
    actionButton("Ok", "Press Ok",style='padding:8px; font-size:100%')
  ),

  dashboardBody(

    bsModal("modalnew", "Greetings", "Ok", size = "small",
            textOutput("text1")
    )

    )
  )

server <- function(input, output) { 

  observeEvent(input$Ok,{

    patid1 <- as.numeric(input$text)
    print(patid1)



    if (is.na(patid1) == TRUE) { output$text1 <- renderText("Please enter 
    a valid ID# without alphabets or special characters")} else {

      #output$text1 <-renderText("")
      output$text1 <-renderText({paste("You enetered", patid1)})
    }

  })

}

shinyApp(ui, server)

我想做的是当用户点击 bsModal window 上的 Close 按钮时,它应该清除 textInput 文本框中的文本。我不知道如何在 bsModal 消息 window 的关闭按钮上添加反应函数。非常感谢任何帮助。

你不能在运行在客户端的 bsModal 上真正做到这一点,但你可以很容易地在服务器上做到这一点:

server <- function(input, output, session) { 

  observeEvent(input$Ok,{

    patid1 <- as.numeric(input$text)

    # Clear input$text
    updateTextInput(session,"text", value="")


    if (is.na(patid1) == TRUE) { output$text1 <- renderText("Please enter 
    a valid ID# without alphabets or special characters")} else {

      output$text1 <-renderText({
        paste("You enetered", patid1)})
    }

  })

}

shinyApp(ui, server)