2016-10-21 78 views
1

我有一个actionButton叫Ok。当用户点击此按钮时,它将从textInput框中获取输入,并显示带有某条消息的bsModal消息对话框窗口。闪亮的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消息窗口的关闭按钮上添加一个反应函数。任何帮助深表感谢。

回答

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) 
+0

,将做到这一点,非常感谢:) –