BISWANKAR DAS kiit
BISWANKAR DAS kiit

Reputation: 13

How to break line inside a paste0() function in shiny dashboard

I'm trying to print 2 lines of text in shinydashboard server section, and "\n" doesn't seem to work

    output$textbox_ID <- renderText(
    {
           paste0("Apples \n Bananas")
    }
    )

Upvotes: 0

Views: 3654

Answers (2)

Greg3er
Greg3er

Reputation: 35

Easiest and no HTML involved:

 paste0("Apples ","\n", "Bananas") # 

Upvotes: -1

A. Suliman
A. Suliman

Reputation: 13125

First of all \n is unicode line break, for shiny you need HTML line break i.e. <br>. Here is a solution using renderUI since I am not sure if it is possible to insert HTML tags in renderText.

UI

uiOutput('textbox_ID')

Server

output$textbox_ID <- renderUI(
{
  HTML(paste0("Apples",br()," Bananas"))
}

)

If you do not need to retrieve something from the server side, then you can use the following in the UI directly:

helpText( HTML(paste0("Apples",br()," Bananas")))
#OR
HTML("Apples <br> Bananas")

Upvotes: 4

Related Questions