merlinoa/shinyFeedback

Multiple feedbacks doesn't work on 0.1.0

Closed this issue · 3 comments

Hi,

Running the example code provided in the vignette (see below) under shinyFeedback 0.1.0 doesn't produce the intended result: while value==2 correctly triggers feedbackDanger, value==1 fails to trigger feedbackWarning.

I can only use the CRAN release. Is there a workaround?
Thanks for your help,

Julien

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)

Hi,

This is a wonderful concept.

I am also having an issue when trying to use multiple feedback.
When I enter text for the success label, the warning label doesn't show up. If I remove the success text, the warning label does show up initially but isn't removed on success.

Code below, any suggestions on how to fix this greatly appreciated.

Thanks

Iain

ui <- fluidPage(
  useShinyFeedback(), # include shinyFeedback

   textInput(
    "orcid_id",
    "Enter an orcid id", 
    placeholder = "ORCID id should be of the form XXXX-XXXX-XXXX-XXXX"
   )
)

server <- function(input, output) {

   observeEvent(input$orcid_id, ignoreInit = TRUE,{
    feedbackWarning(
     inputId = "orcid_id",
     condition = !str_detect(input$orcid_id,"[:alnum:]{4}-[:alnum:]{4}-[:alnum:]{4}-[:alnum:]{4}"),
      text = "Not a valid ORCID id, should be of the form XXXX-XXXX-XXXX-XXXX"
    )
    feedbackSuccess(
    inputId = "orcid_id",
    condition = str_detect(input$orcid_id,"[:alnum:]{4}-[:alnum:]{4}-[:alnum:]{4}-[:alnum:]{4}"),
     text = "appears valid" # if I remove this, the warning label is shown 
   )
 }) 
 }

shinyApp(ui, server)

Thanks for this issue. Sorry for my slow response. I will take a look at this over the next couple of weeks.

I have added showFeedback() and hideFeedback() functions to shinyFeedback. I think these are easier to use, understand, and maintain than the old feedback() function. You will need to use showFeedback() and hideFeedback moving forward as feedback() has been removed from the dev version of this package. With showFeedback() and hideFeedback() you can just use regular R control flow to show/hide feedback messages. #19 has a little additional detail.

Here is an example of multiple feedback messages for 1 input using the new showFeeback() and hideFeedback() functions.

library(shiny)
library(shinyFeedback)

ui <- fluidPage(
  useShinyFeedback(), # include shinyFeedback
  
  numericInput(
    "myInput",
    "Warn > 3; Danger > 5",
    value = 0
  )
)

server <- function(input, output, session) {
  observeEvent(input$myInput, {
    
    hideFeedback("myInput")
    if (input$myInput > 3 && input$myInput <= 5) {
      showFeedbackWarning(
        inputId = "myInput",
        text = 'warning'
      )
    } else if (input$myInput > 5) {
      showFeedbackDanger(
        inputId = "myInput",
        text = "Danger"
      )
    }
    
  })
}

shinyApp(ui, server)

I am closing this issue because I think it is resolved, but please reopen if you disagree.