첫 번째 슬라이더 입력에 따라 두 번째 슬라이더 입력을 업데이트하는 샘플 코드입니다. 열쇠는
observeEvent(input$bins, {
updateSliderInput(session, "bins2", max=input$bins)
})
전체 코드입니다
library(shiny)
ui <- shinyUI(fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
sliderInput("bins2",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
mainPanel(
plotOutput("distPlot")
)
)
))
server <- shinyServer(function(input, output, session) {
observeEvent(input$bins, {
updateSliderInput(session, "bins2", max=input$bins)
})
output$distPlot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})
shinyApp(ui = ui, server = server)
사용'observeEvent'가와'updateSliderInput' 동적 첫 번째 –
감사의 값에 따라 두 번째 슬라이더를 업데이트 할 수있는 서버 측에서이 아니다 사용자 측에서이 업데이트를 반응적으로 만들 수있는 방법이 있습니까? 업데이트를 빨리하고 싶습니다. – andandandand
업데이트가 매우 빠릅니다. 첫 번째 슬라이더를 드래그하는 동안 두 번째 슬라이더를 변경하려면 솔루션을 보려면 http://stackoverflow.com/questions/37420425/r-reactive-histogram#comment62347964_37420425를 참조하십시오. 슬라이더에 대한 원시 javascript 객체를 수정하지 않으면 ui.R에서 완전히 수행 할 수 없습니다 (링크에서 언급했듯이 Shiny는 기본 구현에 대해'Ion.RangeSlider'를 사용합니다). –