Tom
Tom

Reputation: 127

How to add text formatting like superscript or subscript to a label in a Shiny app?

I've built an app with shinydashboard and would like to format correctly some of the input labels. For example, I have a numeric input like this:

numericInput("input_a", "Label (unit = m2)", value = 1)

I cannot find how to edit the m2 to be .

I have tried to use the expression function, without success:

expression(Label~(unit~=~m^2))

Upvotes: 3

Views: 1847

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389175

Here are two option -

  1. You can copy paste the superscript directly into your text.
  2. Use tags$sup
library(shiny)

ui <- fluidPage({
  fluidRow(
           column(6, numericInput("input_a", "Label (unit = m²)", value = 1)), 
           column(6, numericInput("input_b", HTML(paste0("Label (unit = m",tags$sup("2"), ')')), value = 1))
           )  
})
server <- function(input, output) {}
shinyApp(ui, server)

enter image description here

Upvotes: 5

Related Questions