Search code examples
htmlshinyitalics

Shiny renderText: half italicized, half not?


In my shiny app, I have a textOutput named acronym where I would like to renderText some text which is half non-italicized, half-italicized.

I tried doing it like this:

output$acronym_1 <- renderText(paste("SID SIDE:", tags$em("Siderastrea siderea")))

But this did not get the second half in italics. How do I do this? Thanks in advance.


Solution

  • The following code will produce italicized text

    library(shiny)
    
    ui = fluidPage(uiOutput("htmlText"))
    
    server <- function(input, output)
      output$htmlText <- renderUI(HTML(paste(
        "Non-italic text.", em("Italic text")
      )))
    
    shinyApp(ui, server)
    

    I don't think textOutput is capable of text markup since the output string will be created by cat according to the documentation.

    renderText(expr, env = parent.frame(), quoted = FALSE, outputArgs = list())

    expr An expression that returns an R object that can be used as an argument to cat.