daattali / shinyalert

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

add support for mathjax #57

Closed etiennebacher closed 3 years ago

etiennebacher commented 3 years ago

This PR adds support for MathJax, as requested in #54. Here's an example that works now:

library(shiny)

ui <- fluidPage(
  withMathJax(),
  actionButton("btn", "show modal")
)

server <- function(input, output, session) {
  observeEvent(input$btn, {
    shinyalert(
      text = div("$$\\sqrt{2}$$"),
      html = TRUE
    )
  })
}

shinyApp(ui, server)

I placed the line at the end of the JS function, but I don't have particular reasons for that. Let me know if you want me to change or add something.

daattali commented 3 years ago

Wouldn't this result in a javascript error when withMathJax() isn't called?

etiennebacher commented 3 years ago

I added a condition to avoid this javascript error

daattali commented 3 years ago

Thanks! Please add an entry to the NEWS.md file

etiennebacher commented 3 years ago

Done