【问题标题】:shiny bsModal close button闪亮的 bsModal 关闭按钮
【发布时间】:2017-03-04 08:31:48
【问题描述】:

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

这是代码:

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 窗口上的Close 按钮时,它应该清除textInput 文本框中的文本。我不知道如何在 bsModal 消息窗口的关闭按钮上添加反应功能。非常感谢任何帮助。

【问题讨论】:

    标签: r shiny shinybs


    【解决方案1】:

    在客户端运行的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)
    

    【讨论】:

      猜你喜欢
      • 2017-02-04
      • 1970-01-01
      • 2020-08-12
      • 2015-04-29
      • 2015-04-26
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多