Search code examples
htmlrshinydashboard

Add text in separate lines in shinydashboard sidebar


Im trying to put text in separate lines in shinydashboard sidebar I cant make it work with <br>:

library(shiny)


# Creating a Shiny app
ui <- fluidPage(
  titlePanel("Subset Data by Date Range"),
  sidebarLayout(
    sidebarPanel(
      
      textOutput("date_range_text")
    ),
    mainPanel(
    )
  )
)

server <- function(input, output) {
  
  output$date_range_text <- renderText({
    
      
      paste('<br>','Minimum for Selected Topic:',5,"</br>",
            'Maximum for Selected Topic:',5)
      
  })
}

shinyApp(ui = ui, server = server)

Solution

  • Replace the use of <br> with the HTML function. Updated code is here

    library(shiny)
    
    # Creating a Shiny app
    ui <- fluidPage(
      titlePanel("Subset Data by Date Range"),
      sidebarLayout(
        sidebarPanel(
          htmlOutput("date_range_text")  # Use htmlOutput instead of textOutput
        ),
        mainPanel()
      )
    )
    
    server <- function(input, output) {
      
      output$date_range_text <- renderText({
        
        # Use HTML function to include HTML tags
        HTML(paste('Minimum for Selected Topic:', 5, "<br>",
                   'Maximum for Selected Topic:', 10))
          
      })
    }
    
    shinyApp(ui = ui, server = server)