How to change label color of textInput in Shiny Dashboard

I am working on shiny dashboard form application.I want to change color of text Input as red so that i can show that field as mandatory.However i tried code which is working fine for dateInputbut not for textInput.

I am working on shiny dashboard form application where i want to change color of text Input as red so that i can show that field as mandatory.However i tried code listed below which is working fine for dateInput but not for textInput.

column(3,wellPanel(dateInput('dateTR',format = "dd-mm-yyyy",
label = 'Date*',width = "200px",value = Sys.Date()))),
tags$style(type="text/css", "#dateTR {color : red;}"),

column(3, wellPanel(textInput ('textR', label = "Name*", value = "", width = "200px",placeholder = "--Enter name--"))),
tags$style(type="text/css", "#textR {color: red}"),

For above dateInput its working fine but not for textInput as shown in screenshot i want label :Name to appear in red.

enter image description here


In the case of the dateInput, the id is given to a div that wraps both the label and the input itself. In the case of the textInput however, the id is only passed to the input itself, and not to a div that also wraps the label. Therefore your approach only works for the dateInput.

You could wrap the textInput in a div with an id, and make the text inside that div red. Working example below, hope this helps!

library(shiny)

ui <- fluidPage(
  column(3,wellPanel(dateInput('dateTR',format = "dd-mm-yyyy",
                               label = 'Date*',width = "200px",value = Sys.Date()))),
  tags$style(type="text/css", "#dateTR {color : red;}"),

  column(3, wellPanel(div(id='my_textinput' ,
                          textInput ('textR', label = "Name*", value = "", width = "200px",placeholder = "--Enter name--")))),
  tags$style(type="text/css", "#my_textinput {color: red}")
)

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

}

shinyApp(ui, server)

enter image description here