一种方法是使用 javascript 覆盖 CSS 类:
要将其更改为红色,将使用以下 JS 片段:document.getElementById('Pop').style.border = 'solid red"
因此,要将它与您的输入一起使用,您可以编写:
paste0("document.getElementById('Pop').style.border = 'solid ", tolower(input$TagColor) ,"'")
要将其包含在您闪亮的应用程序中,您可以使用shinyjs
包裹。
完整的应用程序:
library(shiny)
library(shinyjs)
ui<-shinyUI(
fluidPage(
useShinyjs(),
selectInput("TagColor", "Color of my Tag",choices=c("Red","Blue",
"Yellow","Black", "initial"),
selected = "Red", multiple = FALSE),
textInput("Pop", "Var1", "Test")
)
)
#
server<-shinyServer(function(input, output) {
observe({
color <- paste0("solid ", tolower(input$TagColor))
if(color == "solid initial") color <- ""
runjs(paste0("document.getElementById('Pop').style.border =
'", color ,"'"))
})
})
shinyApp(ui,server)