1

I want to add one tabulation to a line in Shiny but I don't find the way to do it.

image 1

I know that there are HTML tags in Shiny such as strong to put words in bold, small to make them smaller... Even blockquote to add blocks of quotes. But I didn't find one to add one tabulation.

Does anyone know how to do it?

Reproducible code:

library(shiny)
ui = pageWithSidebar(
  headerPanel("My app"),
  sidebarPanel(
    
  ),
  mainPanel(
            htmlOutput("text")
  )
)
server = function(input, output) {
  output$text <- renderUI({
    str1 <- strong("This is the first line in bold:")
    str2 <- em("This is the second line in italics and with one tabulation")
                
    HTML(paste(str1, str2, sep = '<br/>'))
    
  })
}

shinyApp(ui,server)
Ivar
  • 6,138
  • 12
  • 49
  • 61
emr2
  • 1,436
  • 7
  • 23
  • I'm not sure if this points in the right direction, but this question on tabs might help: https://stackoverflow.com/questions/22509684/r-shiny-tab-symbol-t-in-h4 – Silentdevildoll Jan 12 '22 at 17:34

2 Answers2

1

You could do it just using html code instead of the r tags from shiny:

library(shiny)
ui = pageWithSidebar(
  headerPanel("My app"),
  sidebarPanel(
    
  ),
  mainPanel(
    htmlOutput("text")
  )
)
server = function(input, output) {
  output$text <- renderUI({
    str1 <- "<p><strong>This is the first line in bold:</strong></p>"
    str2 <- "<p style='text-indent: 45px'><em>This is the second line in italics and with one tabulation</em></p>"
    
    HTML(paste(str1, str2, sep = ''))
    
  })
}

shinyApp(ui,server)

unless I have misunderstood what you're trying to do.

enter image description here

DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25
1

You can add a style attribute to each shiny-tag:

library(shiny)
ui = pageWithSidebar(
  headerPanel("My app"),
  sidebarPanel(),
  mainPanel(
    htmlOutput("text")
  )
)
server = function(input, output) {
  output$text <- renderUI({
    tag1 <- p(strong("This is the first line in bold:"))
    tag2 <- p(em("This is the second line in italics and with one tabulation"), style = "text-indent: 1em;")
    HTML(paste(tag1, tag2, sep = '<br/>'))
  })
}

shinyApp(ui,server)

result

ismirsehregal
  • 30,045
  • 5
  • 31
  • 78