Seyma Kalay
Seyma Kalay

Reputation: 2861

shinyapp make bold in ui

I would like to make a few bold words in UI in the sentence. I am not sure how HTML tags will work under h(). any help will be appreciated. many thanks in advance.

library(shiny)
    ui <- navbarPage(
      title = 'Benvenuto',
      tabPanel('read.me', icon = icon("book-open"),  column(4,
                                                            
                                                            h3("Welcome to Interactive User Interface"),
                                                            
                                                            tags$b("Please wait/refresh.", style="color:red"),
    
                                                            h3("Table"),
                                                            h4("Pivot table."),
                                                            
                                                            h2("I HAVE A LONG SENTENCE HERE AND I WANT A FEW WORDS TO BE BOLD ONLY."),
                                                        
      )), 
    
      tabPanel('Table', icon = icon("table"), rpivotTableOutput("pivot") ),
      id="navbar" )
    
    server <- function(input, output) {
    
      output$pivot <- renderRpivotTable({
        rpivotTable(data =   mtcars,  
                    rows = "cyl",
                    cols = c("am", "gear", "carb"),
                    #vals = "Freq", aggregatorName = "Count", rendererName = "Table", subtotals = TRUE) # use this or below line
                    #aggregatorName = "Sum as Fraction of Columns", vals = "Freq", rendererName = "Table Barchart")
                    aggregatorName = "Sum as Fraction of Rows", vals = "cyl", rendererName = "Table With Subtotal")
        #width="200%", height="600px")
        
      })
    
    }
    shinyApp(ui, server)

Expected Answer, I HAVE A LONG SENTENCE HERE AND I WANT A FEW WORDS TO BE BOLD ONLY

Upvotes: 1

Views: 1571

Answers (2)

GGamba
GGamba

Reputation: 13680

h() functions (or almost any html tag function) takes any number of arguments. You can compone your header how you want, including inserting bold words, variables, function results:

library(htmltools)


var <- 'Variable'
f <- function(x) {
  x + 42
}

h4("I HAVE A LONG SENTENCE",
   tags$s("HERE"),
   "AND I WANT",
   tags$i( f(4), "WORDS"),
   "TO BE ",
   tags$b("BOLD"),
   "ONLY,",
   "AND A VARIABLE: ",
   code(var))
I HAVE A LONG SENTENCE HERE AND I WANT 46 WORDS TO BE BOLD ONLY, AND A VARIABLE: Variable

Created on 2020-11-25 by the reprex package (v0.3.0)

Upvotes: 4

henryn
henryn

Reputation: 1237

You can use the HTML function to just use tags like this:

HTML("<h2>I HAVE A LONG SENTENCE HERE AND I WANT <b>A FEW WORDS</b> TO BE BOLD ONLY.</h2>")

Upvotes: 2

Related Questions