1
我正在创建一个反应灵敏的应用程序,它有几个numericInput
变量和一些selectInput
变量。Shiny R:更改selectInput的边框颜色
由于变量相当多,它们用于估计干预措施,所以我引入了颜色来表示与默认设置不同的变量。我已经在@BigDataScientist的this问题的帮助下实现了这个。一个MWE提出:
library(shiny)
library(shinyjs)
ui<-shinyUI(
fluidPage(
useShinyjs(),
numericInput("V1", "MyV1" , value = 5, min = 0, max= 100, step = 0.01),
numericInput("V2", "MyV2" , value = 23, min = 0, max= 100, step = 0.01),
selectInput("V3" , "MyV3" , selected = 1 , choices=c("Yes" = 1,"No" = 0))
)
)
#
server<-shinyServer(function(input, output) {
observe({
if(!is.na(input$V1) & input$V1 != 5){color <- "solid #9999CC"}else{color <- ""}
runjs(paste0("document.getElementById('V1').style.border ='", color ,"'"))
if(!is.na(input$V2) & input$V2 != 23){color <- "solid #9999CC"}else{color <- ""}
runjs(paste0("document.getElementById('V2').style.border ='", color ,"'"))
if(!is.na(input$V3) & input$V3 != 1){color <- "solid #9999CC"}else{color <- ""}
runjs(paste0("document.getElementById('V3').style.borderColor ='", color ,"'"))
})
})
#
shinyApp(ui,server)
正如你可以在下面的图中看到的,我的代码工作的数值,但是它不的选择输入变量(在一个互动的环境至少)。
现在是不是该条件不起作用,其被评估和runjs
运行。
另外,正如你在下面的js代码片段中看到的那样,js命令就好了。可能有办法使它无效(没有提交按钮完全与numericInput),我想念。
<!DOCTYPE html>
<html>
<body>
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<p>Click the button to change the style of the H1 element.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
document.getElementById("mySelect").style.borderColor = "red";
}
</script>
</body>
</html>
你有什么建议吗?
所以如果它不是固体,没有selectize.js,它的工作原理!好的,非常感谢! 它也可以是: 'if(!is.na(input $ V3)&input $ V3!= 1){color < - “solid#9999CC”} else {color < - “”} runjs(paste0 (“document.getElementById('V3')。style.border ='”,color,“'”))' –