6

I have a dialogue in shiny that allows the user to input credentials for a database.

The problem is that the module is opened inside of a called function, therefore somehow I need to pause the function from continuing until the user has put input the required fields. I have tried using req and can not make it work, observeEvent() also does not work since I can not return anything from that environment.

If I do not pause the program somehow, the function keeps on going without the username and password and will not get the data. The trigger to "un-pause" would be an input$Submit, the button in the Modal.

library(shiny)

ui<-
  fluidPage(
    sidebarLayout(position="left",
              sidebarPanel("Parameters",width = 4,
                radioButtons("Type","Test", choices= list("Test"="p", 
                                                         "Test"="l")),
                actionButton("GO","Open Modual")
              ),
              mainPanel(
                plotOutput("Test")

              )))

server<- function(input,output){

 Credential<-function(Test){

 showModal(modalDialog( 
  title = "Credentials Required",
  textInput("Username", "Enter User Name", value = ""),
  textInput("Password", "Enter Password:", value = ""),
  footer =  actionButton("Submit", "Submit"),
  modalButton("Cancel"))
 )

#Use Assigned Username and Password to go fetch data.
#Note data must be returned, somehow need to pause or somthing here.

  }   

  #Call Function
  observeEvent(input$GO,{
  data <- Credential("Test")
  })

}
shinyApp(server=server,ui=ui)

Any ideas?

Thanks,

-Chaboes

Chabo
  • 2,842
  • 3
  • 17
  • 32
  • Have you seen the example on the [modalDialog help page](https://shiny.rstudio.com/reference/shiny/latest/modalDialog.html)? You just need to listen to the button of the form outside the display. You can't "pause" a function like that. – MrFlick Jul 09 '18 at 19:36
  • @MrFlick I have looked at the docs, unfortunately their example uses `observeEvent` to monitor the button, which I would usually do except for the need to return an object from the function. – Chabo Jul 09 '18 at 19:43
  • 1
    Maybe you want something like [shinyalert](https://cran.r-project.org/web/packages/shinyalert/README.html). But still that input is going to happen asynchronously so the function won't be able to return the value. You'd have to set up some sort of call back or update a special reactive value to know when the form is submitted. It would be easier to design this in a more reactive way. – MrFlick Jul 09 '18 at 20:06

0 Answers0