[英]Update sliderInput in Shiny reactively
I am trying to change the values from a sliderInput
dynamically. 我正在尝试动态更改sliderInput
的值。 The difficulty now is that I want to change from a sliderInput
with one value, to a sliderInput
with a range, which seems not to work. 现在的困难是,我想从一个改变sliderInput
一个值,在sliderInput
有一个范围,这似乎不工作。
The first actionbutton in the code below works, while the second does not what it is intended to do. 下面的代码中的第一个动作按钮起作用,而第二个动作按钮不是它的目的。
Is the only possibility to switch to an uiOutput
element? 是否唯一可能切换到uiOutput
元素?
Code 码
library(shiny)
app <- shinyApp(
ui = bootstrapPage(
sliderInput("sld1", min = 0, max = 10, label = "y1", value = 5),
actionButton("acb1", "Change Value"),
actionButton("acb2", "Change Value to Range")
),
server = function(input, output, session) {
observeEvent(input$acb1, {
updateSliderInput(session, "sld1", value = 2)
})
observeEvent(input$acb2, {
updateSliderInput(session, "sld1", value = c(2,7))
})
})
runApp(app)
You can maybe add the slider dynamically using renderUI
您可以使用renderUI
动态添加滑块
#rm(list = ls())
library(shiny)
app <- shinyApp(
ui = bootstrapPage(
uiOutput("myList"),
actionButton("acb1", "Change Value"),
actionButton("acb2", "Change Value to Range")
),
server = function(input, output, session) {
slidertype <- reactiveValues()
slidertype$type <- "default"
observeEvent(input$acb1,{slidertype$type <- "normal"})
observeEvent(input$acb2, {slidertype$type <- "range"})
output$myList <- renderUI({
if(slidertype$type == "normal"){
sliderInput("sld1", min = 0, max = 10, label = "y1", value = 2)
}
else if(slidertype$type == "range"){
sliderInput("sld1", min = 0, max = 10, label = "y1", value = c(2,7))
}
else{
sliderInput("sld1", min = 0, max = 10, label = "y1", value = 5)
}
})
})
runApp(app)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.