我有一个基本的闪亮应用程序可以评估A + B:
library(shiny)
ui <- fluidPage(
numericInput(inputId = "A", label = "A", value = 5, step = 1),
sliderInput(inputId = "B", label = "B", min = 0, max = 10, value = 5),
textOutput(outputId = "value")
)
server <- function(input, output) {
output$value <- renderText(paste0("A + B = ", input$A + input$B))
}
shinyApp(ui = ui, server = server)
A is a numericInput
值和B is a sliderInput
value.
我想限制我的应用程序,以便最大输入值B始终为 2 *A。因此,我必须更改硬编码max =
in sliderInput
到一些可以动态的东西。我怎样才能做到这一点?
Thanks
您可以致电updateSliderInput
更改 B 的最大值observe
每当 A 发生变化时就会触发:
library(shiny)
ui <- fluidPage(
numericInput(inputId = "A", label = "A", value = 5, step = 1),
sliderInput(inputId = "B", label = "B", min = 0, max = 10, value = 5),
textOutput(outputId = "value")
)
# Notice the session argument to be passed to updateSliderInput
server <- function(input, output, session) {
output$value <- renderText(paste0("A + B = ", input$A + input$B))
observe(updateSliderInput(session, "B", max = input$A*2))
}
shinyApp(ui = ui, server = server)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)