简体   繁体   English

如何在Shiny Dashboard中更改textInput的标签颜色

[英]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. 我正在使用闪亮的仪表板表单应用程序。我想将文本输入的颜色更改为红色,以便我可以将该字段显示为必填字段。但是我尝试了对dateInput有效但对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. 对于上述dateInput来说,它的工作正常,但对于textInput却不能,如屏幕截图所示,我希望标签:Name以红色显示。

在此处输入图片说明

In the case of the dateInput , the id is given to a div that wraps both the label and the input itself. 如果使用dateInput ,则将id赋予包装标签和输入本身的div。 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. 但是,在textInput的情况下,id仅传递给输入本身,而不传递给同样包裹标签的div。 Therefore your approach only works for the dateInput . 因此,您的方法仅适用于dateInput

You could wrap the textInput in a div with an id, and make the text inside that div red. 您可以将textInput包装在具有ID的div ,并使该div的文本div红色。 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)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM