【问题标题】:Getting error while using ggplot with r-shiny将 ggplot 与 r-shiny 一起使用时出错
【发布时间】:2021-04-16 10:20:49
【问题描述】:

我正在尝试开发我的第一个 R 闪亮应用。我正在尝试让用户可以决定他想看哪一年。

我运行的错误是:

Warning: Error in : Problem with `filter()` input `..1`.
x Input `..1` must be of size 1026 or 1, not size 0.
i Input `..1` is `leto == input$leto`.
  184: <Anonymous>

我的服务器代码是:

library(shiny)
library(ggplot2)

function(input, output) {
  
  output$graf_dejavnosti <- renderPlot({
    graf_dejavnosti <- ggplot(gospodarskadejavnost %>% 
                                filter(leto == input$leto)) + 
      aes(x=oznaka, y=placa, fill=spol) +
      geom_col(position = "dodge") + guides(fill=guide_legend("Leto")) +
      labs(title = "Plače po dejavnosti in spolu") + theme(plot.title = element_text(hjust = 0.5)) +
      ylab("Plača") + xlab("Dejavnosti") + coord_flip()
    print(graf_dejavnosti)
  })
  output$legenda <- renderTable(gospodarskadejavnost %>%
                                  select(oznaka, dejavnost) %>% unique())
}

我的用户界面代码是:

library(shiny)

fluidPage(
  titlePanel(""),
  
  tabPanel("Graf",
           sidebarPanel(
             selectInput("Leto", label = "Izberi leto", 
                         choices = unique(gospodarskadejavnost$leto))),
           mainPanel(plotOutput("graf_dejavnosti"),
                     tableOutput("legenda")))
  
)

感谢您的帮助!

【问题讨论】:

    标签: r ggplot2 shiny


    【解决方案1】:

    我认为这是因为您将 UI 元素称为“Leto”,所以您的服务器代码应该是:

    filter(leto == input$Leto))
    

    假设您的其余代码是正确的,并且 leto 是您数据框中列的正确名称。

    【讨论】:

      猜你喜欢
      • 2017-01-25
      • 2015-03-02
      • 2020-07-03
      • 2018-11-18
      • 1970-01-01
      • 2020-07-25
      • 2013-11-27
      • 2012-10-30
      • 2019-10-17
      相关资源
      最近更新 更多