问题描述
我想基于 selectInput
输出。
这个想法是要显示,基于交互式文本的另一个选择,新的数据是什么。文本本身由我管理( updateTextInput
)。我想为他们的标签做类似的事情,因为不是所有的 textInput
都改变了。
The idea is to show, what data in new based on another selection for interactive text. The text itself, I have managed (updateTextInput
). I would like to do something similar for their label as not all textInput
change.
因此,如何根据<$ c中指示的颜色更改 Pop
textInput的颜色$ c> TagColor 输入,然后再次将颜色重置为其默认样式?
So, how do I change the colour of the Pop
textInput based on the colour indicated from the TagColor
input, and then again, how do I reset the color to its default style?
library(shiny)
ui<-shinyUI(
fluidPage(
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) {
})
shinyApp(ui,server)
推荐答案
一种方法是使用javascript覆盖CSS类:
要将其更改为红色,以下JS代码段将被使用:
document.getElementById('Pop')。style.border ='纯红色
One way would be to use javascript to overwrite the CSS class:To change it to red, the following JS snippet would be used:document.getElementById('Pop').style.border = 'solid red"
要在输入中使用它,您会这样写:
So to use it with your input you would write:
paste0( document.getElementById('Pop') .style.border ='solid,tolower(input $ TagColor),')
要将其包含在闪亮的应用程序中,您可以使用 shinyjs
包。
To include that in your shiny app you can use the shinyjs
package.
f完整应用程序:
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)
这篇关于闪亮的R:textInput的条件样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!