具有少量值的闪亮 R 滑块
shiny R slider with few values
我需要在绘制直方图时使用滑块。问题是,当我使用它时它并不是很好。此处唯一的工作值(从 1 到 36)是 3、5、9、25、36。因此,我想更改滑块并仅提供这些值。
这是我的代码:
客户
h2('Percentuale di cacao'),
# Slider per l'istogramma della percentuale di cacao
sidebarLayout(
sidebarPanel(
sliderInput("bins1", "Number of bins:", min = 1, max = 36, value = 10),
),
# Plot dell'istogramma
mainPanel(
plotOutput("distPlot1")
)
),
服务器
output$distPlot1 <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins1)
hist(chocolate$CocoaPerc, nclass = input$bins1, xlab="Percentuale di cacao", main="Frequenza della percentuale
di cacao", col = c("chocolate", "chocolate3", "chocolate2", "chocolate4"))
})
我看到一些用户回答使用 shinyWidgets 的其他问题,但在看到文档后,我仍然不知道如何将它放在这里。你能帮帮我吗?
是的,您可以使用 shinyWidgets
包中的 sliderTextInput
。
您为选择提供不同的值,当您在输入中获取值作为文本时,您必须在使用前将它们转换为数字。
UI
...
sliderTextInput("bins1", "Number of bins:", choices=c("3", "5", "9", "25", "36"))
...
服务器
...
bins <- seq(min(x), max(x), length.out = as.integer(input$bins1))
... nclass = as.integer(input$bins1) ...
...
我需要在绘制直方图时使用滑块。问题是,当我使用它时它并不是很好。此处唯一的工作值(从 1 到 36)是 3、5、9、25、36。因此,我想更改滑块并仅提供这些值。 这是我的代码: 客户
h2('Percentuale di cacao'),
# Slider per l'istogramma della percentuale di cacao
sidebarLayout(
sidebarPanel(
sliderInput("bins1", "Number of bins:", min = 1, max = 36, value = 10),
),
# Plot dell'istogramma
mainPanel(
plotOutput("distPlot1")
)
),
服务器
output$distPlot1 <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins1)
hist(chocolate$CocoaPerc, nclass = input$bins1, xlab="Percentuale di cacao", main="Frequenza della percentuale
di cacao", col = c("chocolate", "chocolate3", "chocolate2", "chocolate4"))
})
我看到一些用户回答使用 shinyWidgets 的其他问题,但在看到文档后,我仍然不知道如何将它放在这里。你能帮帮我吗?
是的,您可以使用 shinyWidgets
包中的 sliderTextInput
。
您为选择提供不同的值,当您在输入中获取值作为文本时,您必须在使用前将它们转换为数字。
UI
...
sliderTextInput("bins1", "Number of bins:", choices=c("3", "5", "9", "25", "36"))
...
服务器
...
bins <- seq(min(x), max(x), length.out = as.integer(input$bins1))
... nclass = as.integer(input$bins1) ...
...