daattali / shinyalert

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

Error in html && nzchar(params[["text"]]) : 'length = 3' in coercion to 'logical(1)' #80

Closed BajczA475 closed 5 months ago

BajczA475 commented 9 months ago

I have the following shinyalert() call:

shinyalert(title = "",  #The header
               className = "infoPopUps", 
               immediate = TRUE, 
               animation = TRUE, 
               confirmButtonText = "Done", 
               closeOnClickOutside = TRUE, 
               showConfirmButton = TRUE, 
               text = div(
                   paste0(
                   "Here's a list of all the unique taxa observed in records currently showing in the table: <br><br><em>",
                    choppedtaxa3,
                     "</em>"),
                  class = "infoPopUpsText"),
               html=TRUE
              )

When I run this, I get the error in the title, although I didn't used to.

Here is a dput() of the object choppedtaxa3:

"<em>Brasenia schreberi<br> Nuphar variegata<br> Nymphaea odorata<br> Potamogeton pusillus<br> Sagittaria spp.<br> Schoenoplectus spp.<br> <span class=\"color_invasives\">Typha angustifolia</span><br> Utricularia vulgaris</em><br><em>Carex spp.<br> Ceratophyllum demersum<br> Chara spp.<br> Eleocharis acicularis<br> Eleocharis smallii<br> Elodea canadensis<br> Elodea spp.<br> Heteranthera dubia<br> Hippuris vulgaris<br> Iris versicolor<br> Lemna minor<br> Lemna trisulca<br> Myriophyllum sibiricum<br> Najas flexilis<br> Najas spp.<br> Nitella spp.<br> Nuphar variegata<br> Nymphaea odorata<br> <span class=\"color_invasives\">Potamogeton crispus</span><br> Potamogeton friesii<br> Potamogeton natans<br> Potamogeton richardsonii<br> Potamogeton spp.<br> Potamogeton zosteriformis<br> Protected Species 2<br> Ranunculus spp.<br> Sagittaria latifolia<br> Sagittaria spp.<br> Schoenoplectus acutus<br> Schoenoplectus spp.<br> Spirodela polyrhiza<br> Stuckenia pectinata<br> <span class=\"color_invasives\">Typha angustifolia</span><br> Typha spp.<br> Utricularia spp.<br> Utricularia vulgaris<br> Vallisneria americana<br> Zizania palustris</em><br><em>Ceratophyllum demersum<br> Elodea canadensis<br> Heteranthera dubia<br> Lemna minor<br> Najas flexilis<br> Najas spp.<br> <span class=\"color_invasives\">Potamogeton crispus</span><br> Potamogeton spp.<br> Potamogeton zosteriformis<br> Spirodela polyrhiza<br> Stuckenia pectinata<br> Wolffia spp.</em><br>"

So, it is a single string containing HTML tags. So, length of params[['text']] doesn't seem like it should be > 1 to me.

The issue seems to be with the html parameter, as when I remove it, the error doesn't occur (although I also don't get the proper contents of the modal, as it just says Object object in it instead).

I'm not sure what else to try--I'm not sure if this is a bug or an error on my part!

BajczA475 commented 9 months ago

An update. If I do the div manually using pure HTML like so:

shinyalert(title = "",  #The header
               className = "infoPopUps", 
               immediate = TRUE, 
               animation = TRUE, 
               confirmButtonText = "Done", 
               closeOnClickOutside = TRUE, 
               showConfirmButton = TRUE, 
               text = paste0("<div class = 'infoPopUpsText'>Here's a list of all the unique taxa observed in records currently showing in the table: <br><br><em>", choppedtaxa3, "</em></div>"),
               html=TRUE
               )

Then everything works as intended. Otherwise, when running the code as I was before through the code in the shinyalert() function, I do get this:

> length(params$text)
[1] 3
> params$text[1]
$name
[1] "div"

> params$text[2]
$attribs
$attribs$class
[1] "infoPopUpsText"

> params$text[3]
$children
$children[[1]]
[1] "Here's a list of all the unique taxa observed in records currently showing in the table: <br><br><em><em>Brasenia schreberi<br> Nuphar variegata<br> Nymphaea odorata<br> Potamogeton pusillus<br> Sagittaria spp.<br> Schoenoplectus spp.<br> <span class=\"color_invasives\">Typha angustifolia</span><br> Utricularia vulgaris</em><br><em>Carex spp.<br> Ceratophyllum demersum<br> Chara spp.<br> Eleocharis acicularis<br> Eleocharis smallii<br> Elodea canadensis<br> Elodea spp.<br> Heteranthera dubia<br> Hippuris vulgaris<br> Iris versicolor<br> Lemna minor<br> Lemna trisulca<br> Myriophyllum sibiricum<br> Najas flexilis<br> Najas spp.<br> Nitella spp.<br> Nuphar variegata<br> Nymphaea odorata<br> <span class=\"color_invasives\">Potamogeton crispus</span><br> Potamogeton friesii<br> Potamogeton natans<br> Potamogeton richardsonii<br> Potamogeton spp.<br> Potamogeton zosteriformis<br> Protected Species 2<br> Ranunculus spp.<br> Sagittaria latifolia<br> Sagittaria spp.<br> Schoenoplectus acutus<br> Schoenoplectus spp.<br> Spirodela polyrhiza<br> Stuckenia pectinata<br> <span class=\"color_invasives\">Typha angustifolia</span><br> Typha spp.<br> Utricularia spp.<br> Utricularia vulgaris<br> Vallisneria americana<br> Zizania palustris</em><br><em>Ceratophyllum demersum<br> Elodea canadensis<br> Heteranthera dubia<br> Lemna minor<br> Najas flexilis<br> Najas spp.<br> <span class=\"color_invasives\">Potamogeton crispus</span><br> Potamogeton spp.<br> Potamogeton zosteriformis<br> Spirodela polyrhiza<br> Stuckenia pectinata<br> Wolffia spp.</em><br></em>"

So, the div itself, its class attribute, and its contents are being stored as separate items, causing the length of params$text to be 3 instead of one.

Maybe this is all as it should be, but so far as I know, using a div() call as the input to the text parameter had been working just fine before, so perhaps an update caused a change in consequences here. Thought this extra content might help to sort out whether this is desirable behavior or not here!

janlisec commented 8 months ago

Are you using the CRAN (3.0.0) or the github version (3.0.0.9000) of shinyalert?

I believe the error you describe is fixed in 3.0.0.9000. At least, I can run your example in a shiny app without problems using 3.0.0.9000.

BajczA475 commented 8 months ago

Hi, thanks for responding. I think I was using the CRAN version, yes. I have since switched to a different implementation of modals, but it's good to know that I could grab the Github release and switch back!

Cheers, A



UPDATED AUGUST 2023 Check out my two most recent articles: Why everything you've probably been taught about outliers is wrong https://alexbajcz.com/2023/08/14/youve-probably-been-trained-to-think-about-outliers-all-wrong-and-you-need-to-stop/ and a deep-dive on all things "logistic regression" for analyzing binary data https://alexbajcz.com/2023/07/20/how-to-understand-logistic-and-binomial-regressions-an-applied-crash-course-for-ecologists/ .

Also, see here for an online copy of my Graduate Research Project Checklist for graduate students! https://alexbajcz.com/2023/07/26/checklist-for-completing-a-graduate-level-scientific-research-project-a-thesis-or-dissertation/ And click here to access my R Shiny Manual, complete with example code! https://alexbajcz.com/2023/05/30/rshinymanual/



Dr. Alex W. Bajcz ("badges;" he/him), Quantitative Ecologist Minnesota Aquatic Invasive Species Research Center (MAISRC) Department of Fisheries, Wildlife, and Conservation Biology (FWCB) College of Food, Agriculture, and Natural Resource Sciences (CFANS) Skok Hall, Room 220 University of Minnesota, St. Paul Campus 2003 Upper Buford Circle, St. Paul, MN 55108 bajcz003 at umn.edu 612-626-9549 (please leave a message if I don't answer)

On Thu, Jan 11, 2024 at 7:58 AM JaLi @.***> wrote:

Are you using the CRAN (3.0.0) or the github version (3.0.0.9000) of shinyalert?

I believe the error you describe is fixed in 3.0.0.9000. At least, I can run your example in a shiny app without problems using 3.0.0.9000.

— Reply to this email directly, view it on GitHub https://github.com/daattali/shinyalert/issues/80#issuecomment-1887215607, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADXFUHHP4BKJNY5ABD2UUBLYN7VW7AVCNFSM6AAAAAA7UXI5OCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBXGIYTKNRQG4 . You are receiving this because you authored the thread.Message ID: @.***>

daattali commented 5 months ago

@janlisec is right, you are likely using the CRAN version that does not have this feature yet. By installing the latest github version you'll fix the issue

daattali commented 4 months ago

@BajczA475 I submitted a new version to CRAN today, so in a few days you should be able to install from CRAN