1

I want to have a line break inside a renderText(), but none of the ways I know work. This is a short, reproduceable (and dull) example:

library(shiny)

ui <- fluidPage(
  textOutput("textOut")
)

server <- function(input, output) {
  output$textOut <- renderText({
    paste0("First line", "\nSecond Line", "<br>Third Line")
  })
}

shinyApp(ui, server)

However, this gave me:

First line Second Line<br>Third Line

I've tried \n, \br, <br>, </br>, <\br, <br><\br>, etc. I've even tried using %>% lapply(htmltools::HTML), but nothing seems to work.

I want to avoid using renderHTML(), but if it's the only way, then that's fine. Also, I do not want to make multiple renderText()s – that really is a last-case scenario, because it's tedious, it consumes too many variable names and can't possibly be the optimal solution.

Érico Patto
  • 1,015
  • 4
  • 18
  • 2
    Instead of `textOutput` in your `ui` could you use `verbatimTextOutput` instead? Or anything from [this question](https://stackoverflow.com/questions/26368192/how-to-insert-new-line-in-r-shiny-string/26368406) helpful? Also suggests `renderUI` with `HTML`... – Ben Nov 20 '20 at 22:43
  • Yes, `verbatimTextOutput()` did it. Thanks! – Érico Patto Nov 20 '20 at 23:00

0 Answers0