繁体   English   中英

是否有可能更新 noUiSliderInput 中的 step 参数或使其取决于 min 和 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。 例如,也可以设置我们想要 10 个步骤。 谢谢。

这是一个受 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)

它也可以使用类似于在原始 noUiSliderInput 中写入: step = (max - min) / 10但 min 和 max 是输入的当前最大值或具有自动设置步数而不是步距的参数.

谢谢。

这将做你想要的:

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)

你是对的stepupdateNoUiSliderInput中无效,但我们可以使用renderUI创建一个新的,这样你就可以使用step

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM