Error message for wrong username or password

I am trying to build a shiny app where users need to give credentials to connect with database. If users give correct credentials then the app will load and will show a table, but if the credentials are wrong then they will get a message instead of R error.


data <- function(x, y){
  con <- dbConnect(RMySQL::MySQL(), 
                  dbname = "tweater", 
                  host = "", 
                  port = 3306,
                  user = x,
                  password = y)
  users <- dbReadTable(con, "users")

ui <- fluidPage(
  titlePanel(title = "Shiny LogIN"),
           textInput('username', 'User Name'),
           passwordInput('pass', 'Password'),
           actionButton('submit', 'Submit')),

server <- function(input, output, session) {
  y <- eventReactive(input$submit,{
    x <- data(x = input$username, y = input$pass)
  output$table <- renderTable({

shinyApp(ui, server)

How to replace the R error message with an alert when users give wrong credentials? Consider user name as 'student' and password as 'datacamp'.
There might be chance that the username or password is not unique so if(input$username) != 'student' or if(input$pass) != 'datacamp' cann't be used.

I would use base::tryCatch to handle errors.
Exceptions and debugging ยท Advanced R. (

There are many options to show messages/alerts to users on shiny apps.
Some examples might be found in
shinyalerts package

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.