【问题标题】:shiny R slider with few values值很少的闪亮 R 滑块
【发布时间】:2020-09-13 07:28:51
【问题描述】:

我在绘制直方图时需要使用滑块。问题是,当我使用它时,它并不是很好。这里唯一的工作值(从 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 的其他问题,但是在看到文档之后,我仍然不知道如何将它放在这里。你能帮帮我吗?

【问题讨论】:

    标签: r plot shiny slider histogram


    【解决方案1】:

    是的,您可以使用 shinyWidgets 包中的 sliderTextInput。 您为选择提供不同的值,并且当您将输入中的值作为文本获取时,您必须在使用前将它们转换为数字。

    用户界面

    ...
    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) ...
    ...
    

    【讨论】:

    • 它返回给我这个错误:滑块输入错误(“bins1”,“箱数:”,选择= c(“3”,“5”,:未使用的参数(选择= c("3", "5", "9", "25", "36"))
    • 我认为这是一个错字 - 代码应该是 sliderTextInput 而不是 sliderInput
    • Arrgh“复制粘贴”您的代码。太快了:-)。更正了我的答案
    猜你喜欢
    • 2017-04-01
    • 1970-01-01
    • 2018-01-28
    • 2023-02-15
    • 1970-01-01
    • 2013-07-14
    • 2016-11-17
    • 2023-04-01
    • 1970-01-01
    相关资源
    最近更新 更多