我有一个基本的闪亮应用程序来评估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)
Run Code Online (Sandbox Code Playgroud)
A是numericInput值,B是sliderInput值.
我想我的限制应用程序,以便为最大输入值乙始终是2*一个.因此,我必须硬编码的改变max =中sliderInput的东西,可以是动态的.我怎么能做到这一点?
谢谢
您可以调用updateSliderInput以更改B中的最大值,observe只要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")
)
# 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)
Run Code Online (Sandbox Code Playgroud)
你正在寻找 renderUI()
library(shiny)
ui <- fluidPage(
numericInput(inputId = "A", label = "A", value = 5, step = 1),
uiOutput("slider"),
textOutput(outputId = "value")
)
server <- function(input, output) {
output$value <- renderText(paste0("A + B = ", input$A + input$B))
output$slider <- renderUI({
sliderInput(inputId = "B", label = "B", min = 0, max = 2*input$A, value = 5)
})
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1406 次 |
| 最近记录: |