[英]Is there a possibility to update the step parameter in noUiSliderInput or to make it depend on min and max?
Is there a possibility to update the step parameter in noUiSliderInput or to make it depend on min and max.是否有可能更新 noUiSliderInput 中的 step 参数或使其取决于 min 和 max。 It would also work to have a possibility to set that we want 10 steps for instance.
例如,也可以设置我们想要 10 个步骤。 Thanks.
谢谢。
Here is a reproducible example inspired from the updateNoUiSliderInput demo:这是一个受 updateNoUiSliderInput 演示启发的可重现示例:
ui <- fluidPage(
tags$h3("Update method"),
tags$br(),
fluidRow(
panel(
status = "danger", heading = "Update min/max",
noUiSliderInput(
inputId = "to_update_minmax",
label = "Slider disable:",
min = 0, max = 100, value = 50,
colo = "#F2DEDE",
step = 10
),
verbatimTextOutput(outputId = "res_update_minmax"),
actionButton(inputId = "minmax_0_100", label = "Set min=0 & max=100"),
actionButton(inputId = "minmax_1000_5000", label = "Set min=1000 & max=5000")
),
)
)
)
server <- function(input, output, session) {
output$res_update_minmax <- renderPrint(input$to_update_minmax)
observeEvent(input$minmax_0_100, {
updateNoUiSliderInput(
session = session,
inputId = "to_update_minmax",
range = c(0, 100),
step = 10 # this is not a valid argument for updateNoUiSliderInput !!!
)
})
observeEvent(input$minmax_1000_5000, {
updateNoUiSliderInput(
session = session,
inputId = "to_update_minmax",
range = c(1000, 5000)
step = 500 # this is not a valid argument for updateNoUiSliderInput !!!
)
})
}
shinyApp(ui, server)
It would also work with something like writing in the original noUiSliderInput: step = (max - min) / 10
but with min and max being the curent max values of the input or having a argument to set automatically the steps number and not the steps distance.它也可以使用类似于在原始 noUiSliderInput 中写入:
step = (max - min) / 10
但 min 和 max 是输入的当前最大值或具有自动设置步数而不是步距的参数.
Thanks.谢谢。
This will do what you want:这将做你想要的:
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
tags$h3("Update method"),
tags$br(),
fluidRow(
panel(
status = "danger", heading = "Update min/max",
uiOutput("to_update_minmax_wrapper"),
verbatimTextOutput(outputId = "res_update_minmax"),
actionButton(inputId = "minmax_0_100", label = "Set min=0 & max=100"),
actionButton(inputId = "minmax_1000_5000", label = "Set min=1000 & max=5000")
)
)
)
server <- function(input, output, session) {
output$res_update_minmax <- renderPrint(input$to_update_minmax)
output$to_update_minmax_wrapper <- renderUI({
noUiSliderInput(
inputId = "to_update_minmax",
label = "Slider disable:",
min = 0, max = 100, value = 50,
colo = "#F2DEDE",
step = (100 - 0)/10
)
})
observeEvent(input$minmax_0_100, {
output$to_update_minmax_wrapper <- renderUI({
noUiSliderInput(
inputId = "to_update_minmax",
label = "Slider disable:",
min = 0, max = 100, value = 50,
colo = "#F2DEDE",
step = (100 - 0)/10
)
})
})
observeEvent(input$minmax_1000_5000, {
output$to_update_minmax_wrapper <- renderUI({
noUiSliderInput(
inputId = "to_update_minmax",
label = "Slider disable:",
min = 1000, max = 5000, value = mean(c(5000, 1000)),
colo = "#F2DEDE",
step = (5000 - 1000)/10
)
})
})
}
shinyApp(ui, server)
You are right step
is not valid in updateNoUiSliderInput
, but we can use renderUI
to create a new one so you can use step
.你是对的
step
在updateNoUiSliderInput
中无效,但我们可以使用renderUI
创建一个新的,这样你就可以使用step
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.