Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a message box in R Shiny?

I am trying to display messages like "user is authenticated" or "account created" in Shiny with uiOutput, but it overrides the front page of my Shiny dashboard which is not required.

Is there a function in Shiny in which we can add a message box like thing, which can be closed once the message is displayed and then the user can proceed?

like image 654
Kaverisonu Avatar asked Jan 30 '18 14:01

Kaverisonu


People also ask

How do you show a message in Shiny?

Simply call shinyalert() with the desired arguments, such as a title and text, and a modal will show up. In order to be able to call shinyalert() in a Shiny app, you must first call useShinyalert() anywhere in the app's UI.

How do you add text to the Shiny dashboard?

You can use tahs$h1() to h6() to add headings, or add text using textOutput(). You can add text using text within quotes(" ").

Is R Shiny difficult?

Along with Shiny elements, you can use HTML elements to stylize your content in your application. In my opinion, R Shiny is very easy to learn despite how powerful the tool is. If you're working on a side project or looking to add something to your portfolio, I highly recommend trying it out.

What can you do with R Shiny?

Shiny is an R package that makes it easy to build interactive web apps straight from R. You can host standalone apps on a webpage or embed them in R Markdown documents or build dashboards. You can also extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions.


1 Answers

You could use modalDialogs for that, here is a working example:

library(shiny)
ui = fluidPage(
  actionButton("login", "Log in"),
  textInput('userid','User id:',value=' definitely not Florian')
)
server = function(input, output) {
  observeEvent(input$login, {
    showModal(modalDialog(
      title = "You have logged in.",
      paste0("It seems you have logged in as",input$userid,'.'),
      easyClose = TRUE,
      footer = NULL
    ))
  })
}

shinyApp(ui,server)

Hope this helps!

like image 146
Florian Avatar answered Oct 11 '22 03:10

Florian