1
我正在根据用户输入添加样式标签。根据用户选择的单选按钮,selectInput
的边框颜色会发生变化。在下面的示例代码中,如果用户选择单选按钮中的“错误”,并且如果用户选择“无错误”,则将其设置回灰色(默认颜色),则将颜色设置为红色。删除从服务器端添加的样式标签
我面临的问题是,我每次用renderUI
这些标签的风格标签不断被添加到HTML头。理想情况下,我想要做的是删除我之前添加的样式标签。有没有办法做到这一点?
以下是我目前正在使用的代码:
library(shiny)
ui <- fluidPage(
uiOutput("Border_Arg"),
radioButtons("RBtn", "Choices", choices = c("Error", "No Error")),
selectInput("Select1", "Option1", choices = NULL)
)
server <- function(input, output){
output$Border_Arg <- renderUI({
if(input$RBtn == "Error"){
tagList(
tags$head(tags$style(HTML("#Select1 ~ .selectize-control.single .selectize-input {border: 1px solid red;}")))
)
}else if(input$RBtn == "No Error"){
#Here, instead of setting the style to default value I would like to remove the style that was previously added
tagList(
tags$head(tags$style(HTML("#Select1 ~ .selectize-control.single .selectize-input {border: 1px solid #cccccc;}")))
)
}
})
}
shinyApp(ui = ui, server = server)
我不希望我的'selectInput'显示错误。只是我选择的那个。这只是一个示例代码,我的实际应用程序有很多'selectInput'。我没有在我的问题中说清楚,这段代码当然可以回答我的问题。您是否知道一种方法来为某个'selectInput'添加样式并将其删除? – SBista
'addCssClass'确实有'id'参数。不幸的是,它不适用于'select'输入,因为id附加在DOM的隐藏元素上。您可以使用您已有的选择器。更新答案 – GGamba
谢谢。这正是我想要的。 – SBista