skip to Main Content

I’m trying to add a style in shiny but when I check Chrome it shows up as #input-label + div > div {width: 150px}, > should actually be >. What is causing this?

library(shiny)

ui <- fluidPage(
    tags$style("#input-label + div > div {width: 150px;}"),
  numericInputIcon("input", "input", 42, icon = "Num")
)

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

2

Answers


  1. The issue is that you pass a character string which gets escaped, i.e. the > is replaced by the HTM entity &gt;. To prevent that you have to wrap in HTML() so that

    the tag() function will know not to perform HTML escaping on it. (See ?htmltools::HTML).

    This also mentioned in the docs (see ?tags) according to which ... may include

    HTML() strings

    library(shiny)
    library(shinyWidgets)
    
    ui <- fluidPage(
      tags$style(HTML("#input-label + div > div {width: 150px;}")),
      numericInputIcon("input", "input", 42, icon = "Num")
    )
    
    server <- function(input, output, session) {
    
    }
    
    shinyApp(ui, server)
    #> 
    #> Listening on http://127.0.0.1:6399
    

    Login or Signup to reply.
  2. this happens because chrome read the line as html

    try this:

    ui <- fluidPage(
        tags$style(HTML("
            #input + div > div {width: 150px;}
        ")),
        numericInputIcon("input", "Input Label", 42, icon = "Num")
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search