shinyFeedback Introduction

Andy Merlino

2018-08-19

Functionality

The shinyFeedback package displays user friendly message that appear along side shiny inputs. Here are pictures of shiny inputs with feeback messages displayed:

These messages can be helpful for guiding your users on how to use the app.

shinyFeedback currently works with the following shiny::*Input() functions:

Setup

In order to use shinyFeedback you need to include the following function at the top of your UI.

useShinyFeedback()

The above function is the only change you need to make to your shiny UI. All other code changes will occur in the server function.

The following is a minimal example of a shiny app that uses shinyFeedback. Run the following code in your R console to run the app.

library(shiny)
library(shinyFeedback)

ui <- fluidPage(
  useShinyFeedback(), # include shinyFeedback
  
  numericInput(
    "warningInput",
    "Warn if Negative",
    value = 0
  )
)

server <- function(input, output) {
  observeEvent(input$warningInput, {
    feedbackWarning(
      inputId = "warningInput",
      condition = input$warningInput < 0
    )
  })
}

shinyApp(ui, server)

The above app has one numericInput() input in the UI. In the server function, we write the code that will display a feedback message. This feedback message is displayed when the user enters a negative value. It is hidden with the input value is >= 0.

The feedbackWarning() function is what makes this work. Run ? to see more detail on this function:

?feedbackWarning

Going back to our minimal app above, the feedbackWarning() function sits inside a shiny::observeEvent() function. feedback*() functions will always sit inside of these shiny observers. If you are not comfortable using shiny observers, check out the excellent shiny documentation. I also highly recommend the videos from the 2016 Shiny Developer Conference.

The feedback function

The primary function provided by shinyFeedback is feedback(). feedback() creates messages like those shown in the image at the top of this vignette. The color, icon, and text of the feedback message can be customized.

Handy feedback wrappers

shinyFeedback has 3 convenience functions:

The above functions provide default styling options for the feedback messages. These functions are just thin wrappers around the feedback() function. A live app with more examples of these functions is available here.

Multiple feedbacks

When assigning multiple feedback()s to a single input (e.g. you want to display a certain feedback message if the input value >= 1, and a different feedback value if the input is >= 2), place the feedback()s in the same shiny observer. If multiple feedback() function conditions evaluate to TRUE, only the feedback() furthest down in the expression will be displayed.

ui <- fluidPage(
  useShinyFeedback(), # include shinyFeedback
  
  numericInput(
    "multiFeedbacks",
    "1 is scary 2 is dangerous", 
    value = 1
  )
)

server <- function(input, output) {
  observeEvent(input$multiFeedbacks, {
    feedbackWarning(
      inputId = "multiFeedbacks",
      condition = input$multiFeedbacks >= 1,
      text = "Warning 1 is a lonely number"
    )
    feedbackDanger(
      inputId = "multiFeedbacks",
      condition = input$multiFeedbacks >= 2,
      text = "2+ is danger"
    )
  })
}

shinyApp(ui, server)

When the above input is >=2, both feedback*() function conditions are TRUE, but Only the feedbackDanger() is displayed because it is called after the feedbackWarning().