具有少量值的闪亮R滑块

具有少量值的闪亮R滑块,r,plot,shiny,slider,histogram,R,Plot,Shiny,Slider,Histogram,我需要在绘制直方图时使用滑块。问题是,当我使用它时,它不是很好。这里唯一的工作值(从1到36)是3、5、9、25、36。因此,我想更改滑块并仅使这些值可用。 这是我的代码: 客户 服务器 output$distPlot1 <- renderPlot({ x <- faithful[, 2] bins <- seq(min(x), max(x), length.out = input$bins1) hist(chocolate

我需要在绘制直方图时使用滑块。问题是,当我使用它时,它不是很好。这里唯一的工作值(从1到36)是3、5、9、25、36。因此,我想更改滑块并仅使这些值可用。 这是我的代码: 客户

服务器

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"))
    })
...
bins <- seq(min(x), max(x), length.out = as.integer(input$bins1))
... nclass = as.integer(input$bins1) ...
...

output$distPlot1是,您可以使用
shinyWidgets
软件包中的
sliderOutput
。 您为选项提供不同的值,当您以文本形式在输入中获得值时,必须在使用之前将其转换为数字

用户界面

服务器

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"))
    })
...
bins <- seq(min(x), max(x), length.out = as.integer(input$bins1))
... nclass = as.integer(input$bins1) ...
...
。。。

bins它返回给我这个错误:sliderInput中的错误(“bins1”,“bins的数量:”,choices=c(“3”,“5”):未使用的参数(choices=c(“3”,“5”,“9”,“25”,“36”))我认为这是一个输入错误-代码应该是
SliderOutput
,而不是
sliderInput
。argh“复制粘贴”您的代码。太快了:-)。更正了我的答案