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
observeEvent
to monitor the button, which I would usually do except for the need to return an object from the function.