单击“休息”中的“休息”按钮

时间:2018-06-28 06:05:29

标签: r shiny

我正在创建一个用户注册应用程序,它接受用户输入,例如:用户名,姓氏,电子邮件,联系电话。

单击创建按钮后,我能够显示模式消息,说明用户已注册。我要关闭按钮的onclick,我希望创建的tabpanel可以将所有textinput重置为其原始数据。

1)Created one tabpanel with title.
2)Created all the input and its types.
3)Created Modal successfully.
4)Even tried with shinyjs::reset() funtion as well.

Ui.R的代码:

tabPanel(title="User Management",id ="user",shinyjs::useShinyjs(),
       fluidRow(
               column(5,textInput("uname","User Name")),
               column(5,textInput("fname","Full Name"))),
       fluidRow(
                column(5,textInput("email","Email Id")),
                column(5,numericInput("contactnum","Contactnumber",value=NULL))),
        fluidRow(
                column(5,selectInput("country", label = "Country:",
                                      choices = list("India","USA"), 
                                      selected = 1)),
                column(5,selectInput("state", label = "State:",
                                      choices =list("Karnataka","Kerala"), 
                                      selected = 1))),
        fluidRow(column(5,numericInput("zip","ZIP Code",value=NULL)),
        fluidRow(
                  column(5,passwordInput("pwd1","Password")),
                  column(5,passwordInput("pwd2","Confirm Password"))),
        fluidRow(
                  column(12,actionButton("userCreate", "Create User"), 
                  style="color: #fff; 
                  background-color: #337ab7; border-color: #2e6da4"))),
                       br(),
              )
     )

Server.R:

observeEvent(input$userCreate,{
if(postuser() == 200)
{
  showModal(modalDialog(
    title = "Success",
    "User is successfully added!"
   footer = tagList(
        actionButton("Close", "Close")
      )
    )))
}
})

observeEvent(input$Close,{
 reset("user")
}
)

更新和尝试:

Even tried with shinyjs::reset("user") funtion and shinyjs::js$reset("user")function as well.

请帮助我。我需要逻辑代码来列出所有县和州。

预先感谢

1 个答案:

答案 0 :(得分:1)

尝试

observeEvent(input$Close,{
     #reset("user")
     shinyjs::reset("uname")
     shinyjs::reset("fname")  
     #the remaining fields id's you would like to reset
}

问题是给reset赋予了错误的div ID,因此单击close之后没有任何反应。要了解我在说什么,请看

print(tabPanel(title="User Management",id ="user",shinyjs::useShinyjs(),
                  fluidRow(
                      column(5,textInput("uname","User Name")),
                      column(5,textInput("fname","Full Name")))))