Search code examples
htmlrshinyline-breaks

how to add multiple line breaks conveniently in shiny?


I want put multiple line breaks in my shiny app. Instead of

br(),
br(),
br(),
...

is there a more convenient way of doing it?


Solution

  • I have no idea if that's convenient for you, but it saves you some typing.

    linebreaks(n) repeats <br/> n times and parses it as HTML.

    library(shiny)
    
    
    linebreaks <- function(n){HTML(strrep(br(), n))}
    
    ui <- fluidPage(
    
      titlePanel(
                  p( 
                      h1("first sentence", align = "center"),
    
                      linebreaks(10),
    
                      h3("second sentence", align = "center")
                    )
                  )
      )