daattali / shinyalert

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

fix length=3 warning/error #76

Closed r2evans closed 1 year ago

r2evans commented 1 year ago

Per the docs, this should work:

library(shiny)
library(shinyalert)
shinyApp(
ui = fluidPage(
  # useShinyalert()
),
server = function(input, output) {
  shinyalert(html = TRUE, text = tagList(
    textInput("name", "What's your name?", "Dean"),
    numericInput("age", "How old are you?", 30)
  ))
})

Before R-4.3, this now warns

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

and on R-4.3 or newer, this is an error. Regardless, the modal does not appear.

If I uncomment useShinyalert(), I get the message

Warning: Good news!
You don't need to call `useShinyalert()` anymore. Please remove this line from your code.
If you really want to pre-load {shinyalert} to the UI for any reason, use:
    `useShinyalert(force = TRUE)`

and it still does not work. When I add force=TRUE then the alert appears on R-4.2.3 with the aforementioned warning. On R-4.3 it fails completely.

The length issue can be resolved by wrapping the tagList with as.character.

library(shiny)
library(shinyalert)
shinyApp(
ui = fluidPage(
  useShinyalert(force = TRUE)
),
server = function(input, output) {
  shinyalert(html = TRUE, text = as.character(tagList(
    textInput("name", "What's your name?", "Dean"),
    numericInput("age", "How old are you?", 30)
  )))
})

If I use useShinyalert() or if I comment it out completely, the alert does not appear.

This is on shinyalert_3.0.0 with shiny_1.7.4 on R-4.2.3.

(Motivated by https://stackoverflow.com/q/76434476/3358272.)

stla commented 1 year ago

Duplicate of https://github.com/daattali/shinyalert/issues/75.