ui <- fluidPage(
sliderInput("obs", "Number of observations:",
min = 0, max = 1000, value = 500
),
plotOutput("distPlot")
)
# Server logic
server <- function(input, output) {
output$distPlot <- renderPlot({
hist(rnorm(input$obs))
})
}
# Complete app with UI and server components
shinyApp(ui, server)
我有一个带sliderInput
的简单应用,用户可以使用该应用切换并选择观察次数。有没有办法修改它,以便在这个滑块功能的顶部,用户可以将他/她想要的观察数量输入到一个框中,并且该输入将反映在结果直方图中?我希望用户能够灵活地使用滑块,并且能够快速输入精确值,而不必一直依赖滑块。
答案 0 :(得分:1)
这样的东西?
ui <- fluidPage(
numericInput("obs_numeric", "Number of observations", min = 0, max = 500, value = 500),
sliderInput("obs", "Number of observations:",
min = 0, max = 1000, value = 500
),
plotOutput("distPlot")
)
# Server logic
server <- function(input, output, session) {
output$distPlot <- renderPlot({
hist(rnorm(input$obs))
})
observeEvent(input$obs, {
updateNumericInput(session, "obs_numeric", value = input$obs)
})
observeEvent(input$obs_numeric, {
updateSliderInput(session, "obs",
value = input$obs_numeric)
})
}
# Complete app with UI and server components
shinyApp(ui, server)