약간의 numericInput
변수와 일부 selectInput
변수가있는 다소 반응이있는 앱을 만들고 있습니다.Shiny R : selectInput의 테두리 색상 변경
변수가 상당히 많아서 개입을 추정하는 데 사용되므로 기본값과 다른 변수를 나타내는 색을 도입했습니다. 난 이미 this 질문에 @ BigDataScientist의 도움으로 이것을 구현했습니다. 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 (입력 $ V3) & 입력 $ V3! = 1) {색상 <- "고체 # 9999CC"} else {색상 <- ""} runjs (paste0 ("document.getElementById ('V3'). style.border = '", color, "'"))' –