Usage of HTML tags

I am trying yo use the html tags, to highlight the results of a calculation in a table.

I put this code inside the renderTable:

...
texto_tabla <- matrix(c(
paste(tags$h4(formatC(viajes, digits=0, format="f"))," viajes"),
...

What I get as output is this:

351,419

viajes

What am I missing?

What is the expected result?
Could you post an additional reprex expression?

Sorry, I see that the tag was applyed for the post.

What I get is:

<"h4">351,419<"/h4">

...without the quotation marks.

My expected result was the 351,419 in bold, as it appears in the message.

Thanks.

Here is a solution taken from SO

library(shiny)

ui <- fluidPage(
  tableOutput("TBL")

)

server <- function(input, output) {
  viajes <- 351419
  tb <- matrix(c("a",
                 paste0("<strong>",formatC(viajes, digits=0, format="f"), "</strong>"," viajes"),
                 "c", "d"), nrow = 2)
 output$TBL <- renderTable({tb}, sanitize.text.function=function(x){x})
  
}

shinyApp(ui, server)
1 Like

Thanks a lot @FJCC

I get the point that the key is the "sanitize.tect.function..." but it seems to need me to put the calculations out of the renderTable space, and then my table will not update wit the bew figure.

Is the any other way to do that?

This also works.

library(shiny)

ui <- fluidPage(
  tableOutput("TBL")
  
)

server <- function(input, output) {
  
  output$TBL <- renderTable({
    viajes <- 351419
    matrix(c("a",
             paste0("<strong>",formatC(viajes, digits=0, format="f"), "</strong>"," viajes"),
             "c", "d"), nrow = 2)}, sanitize.text.function=function(x){x})
  
}

shinyApp(ui, server)

Works perferc, thanks a lot @FJCC

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.