daattali / shinyalert

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

Editing text color in the modal #34

Closed wwyws0000 closed 4 years ago

wwyws0000 commented 4 years ago

Hi, thank you for developing this package. Is there any way to do some styling with the text in the modal? For example, coloring/highlighting part of the text to make it stand out to the user?

daattali commented 4 years ago

You can provide HTML directly instead of just plain text, so you can add colours or any style you want with HTML.

wwyws0000 commented 4 years ago

You can provide HTML directly instead of just plain text, so you can add colours or any style you want with HTML.

Thank you. Could you provide an example? I'm not experienced enough with using HTML directly in Shiny. I managed to get it to work in modalDialog but for some reason it's not working for shinyalert:

library(shiny)
library(shinyalert)

# Main app UI
ui <- fluidPage(
  useShinyalert()
  ,actionButton('msg1','modalDialog')
  ,actionButton('msg2','Shinyalert')
)

# Main app server
server <- function(input, output, session) {

  observeEvent(input$msg1,{
    showModal(
      modalDialog(
        title = 'modalDialog message'
        ,div(p("This is a message using ",style = 'font-size:160%;display: inline')
             ,p("modalDialog",style = 'font-size:160%; color:red;display: inline'))
      )
    )

  })

  observeEvent(input$msg2,{
    shinyalert(
      title = 'shinyalert message'
      ,div(p("This is a message using ",style = 'font-size:160%;display: inline')
            ,p("shinyalert",style = 'font-size:160%; color:red;display: inline'))
      ,html = TRUE
    )

  })

}

shinyApp(ui, server)

here in the example the modalDialog message has the modified text size and color, while the shinyalert message shows:

image

daattali commented 4 years ago

That looks like it should work. Maybe wrap it in as.character() to make sure you're passing a string.

wwyws0000 commented 4 years ago

Wrapping it in as.character() did the trick, Thank you!