如何修改闪亮的 sliderInput 以便用户可以直接输入值?
How do I modify sliderInput in shiny so user can directly type in value?
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
用户可以切换和 select 观察次数。有没有办法修改它,以便在此滑块功能之上,用户可以在框中输入 his/her 所需的观察次数,并且该输入将反映在生成的直方图中?我希望用户能够灵活地使用滑块,并且能够快速输入准确的值,而不必一直依赖滑块。
是这样的吗?
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)
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
用户可以切换和 select 观察次数。有没有办法修改它,以便在此滑块功能之上,用户可以在框中输入 his/her 所需的观察次数,并且该输入将反映在生成的直方图中?我希望用户能够灵活地使用滑块,并且能够快速输入准确的值,而不必一直依赖滑块。
是这样的吗?
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)