Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

whitespace in R Shiny

I have a problem with text in Shiny Dashboard. I would like to save original text formatting, but shiny removes the whitespaces I want to keep.

output$frame <- renderUI({
    HTML(paste(
               p(strong("Name and Surname:"),("     John Smith"))
               )
         )
  })


tabItem(tabName = "aaa",
        h2("bbb"),
        fluidRow(
                box(width = 6, solidHeader = TRUE, htmlOutput("frame")) 
                )
      ),

Unfortunately I get "Name and Surname: John Smith". I wish to have "Name and Surname: John Smith".

How to solve this problem?

like image 972
tomsu Avatar asked Jan 30 '23 09:01

tomsu


2 Answers

You can use HTML('&nbsp;') to add 1 whitespace and HTML('&emsp;') to add 1 tab space. In your code it wold be as follows:

output$frame <- renderUI({
        HTML(paste(
          p(strong("Name and Surname:"), HTML('&nbsp;'),HTML('&nbsp;'),"John Smith")
        )
        )
      })

With this you get two white spaces and output looks like this: enter image description here

like image 176
SBista Avatar answered Feb 01 '23 09:02

SBista


I found that we can also use stri_dup(intToUtf8(160), 6) from package stringi.

like image 31
tomsu Avatar answered Feb 01 '23 07:02

tomsu