daattali / shinyalert

🗯️ Easily create pretty popup messages (modals) in Shiny
https://daattali.com/shiny/shinyalert-demo/
Other
241 stars 26 forks source link

R 4.2.0: warning in if-condition when using multiline HTML text #68

Closed lgaborini closed 2 years ago

lgaborini commented 2 years ago

Simple reprex:

library(shiny)
library(shinyalert)

ui <- fluidPage(
   actionButton("preview", "Preview")
)

server <- function(input, output, session) {
   observeEvent(input$preview, {

      # Show a modal when the button is pressed
      shinyalert(
         title = "Test",
         html = TRUE,
         text = c(
            "Line1",
            "Line2"
         )
      )

   })
}

shinyApp(ui, server)

The warning is:

Warning in html && nzchar(params[["text"]]) : 'length(x) = 2 > 1' in coercion to 'logical(1)'

daattali commented 2 years ago

@lgaborini thanks for the report. Can you please install latest version and confirm you don't see the warning

lgaborini commented 2 years ago

Confirm fixed, thank you!

BajczA475 commented 1 year ago

I am still getting this warning running version 3.0.0 of this package which looks to be the latest version on CRAN. It looks like this warning has transitioned or will soon be transitioning to an error (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1), which is why I'm writing this here--I'm now getting an error in my shiny app upon clicking the button that triggers my shiny alerts when I wasn't before, and I think it's faulting this chunk in the shinyalert.R script:

if (html && !is.null(params[["text"]]) && (length(params[["text"]]) > 1 || nzchar(as.character(params[["text"]])))) { if (type == "input") { stop("Cannot use 'input' type and HTML together. You must supply your own Shiny inputs when using HTML.", call. = FALSE) }

It looks like how && and || work has shifted in recent updates of R and may now be breaking some previously working code? I see those operators in a few other lines in here also...

Using the reprex in this Thread, I still get a warning, not an error, FWIW.

Edit: Also FWIW, using the reprex here as a base, this is closer to my use case:

observeEvent(input$preview, {
    string2show = paste0(c("Some amount<br>", "Of strings<br>", "Combined<br>"), collapse="")

    # Show a modal when the button is pressed
    shinyalert(
      title = "Test",
      html = TRUE,
      div(HTML("Here's a list of all the lakes with records currently showing in the table: <br><br>", string2show),
          class = "infoPopUpsText")
    )

  })

Still only produces a warning using this reprex but an error in my actual App. Not sure why. EDIT x2: Somehow my warn in options got set to > 2, so all warnings were elevated to errors (https://stackoverflow.com/questions/72754423/how-to-solve-error-converted-from-warning/72754921#72754921). Still, if this warning is going to become an error eventually, worth poking into! :)

daattali commented 1 year ago

Please install the latest dev/GitHub version, the fix is not on CRAN yet

daattali commented 4 months ago

A new version was submitted to CRAN today, it will be on CRAN in a few days