Home > Blockchain >  How to use HTML tags on other tags in Shiny?
How to use HTML tags on other tags in Shiny?

Time:12-09

I am trying to print a title like :

There is 45% available

With 45% in bold like that, and I produced this code :

h4(paste0("There is ", strong(as.character(prctnage)), strong("%"), " available"))

Here is the output :

There is <strong>45<strong><strong>%<strong> available

Any suggestion?

CodePudding user response:

See ?h4: ... arguments expect:

Tag attributes (named arguments) and children (unnamed arguments)

In your example paste0 in h4 converts the tags to a string.

library(shiny)
library(htmltools)

percentage <- 10

ui <- fluidPage(
  h4("There is ", strong(paste0(percentage, "%")), " available"),
  # another option:
  h4(HTML(paste0("There is ", strong(as.character(percentage)), strong("%"), " available")))
)

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

result

Another option would be to mark the characters as HTML again using HTML()

  • Related