【问题标题】:"Error incorrect length (0), expecting: 110" when building shiny app构建闪亮的应用程序时“错误长度不正确(0),期望:110”
【发布时间】:2016-06-02 01:25:39
【问题描述】:

新手在第一个 Shiny 应用上需要一些帮助。 我想过滤几个国家并根据它绘制一个简单的折线图。但我收到错误:“评估错误:长度不正确(0),预期:110 堆栈跟踪(最内层优先)”

这里是代码。谢谢你的帮助:)

ui.r

> shinyUI(fluidPage(   
> titlePanel("Die Selbstmordraten einiger OECD-Staaten"),
>      sidebarLayout(
>     sidebarPanel(         
>     checkboxGroupInput("land", "Land auswählen", choices = c ("Deutschland", "Griechenland", "Ungarn", "Litauen","Luxemburg"))
>     ),
>     mainPanel(
>       plotOutput("plot")
>     ))))

服务器.R

library(shiny)
library(ggplot2)
library(dplyr)


shinyServer(function(input, output, session) {

  filter1<-reactive({
    data%>%
      filter(Land == input$landInput)

  })  

  output$plot<-renderPlot({
    ggplot(filter(), aes(Jahr, Rate, group=Land, colour=Land))+
    geom_line(size=.5)+geom_point()+
    theme(legend.title=element_blank())

    })
})

【问题讨论】:

  • 1) 你没有landInput 只有land 2) 你可能需要%in% 而不是== 3) 你没有反应filter() 只有filter1()
  • 工作正常!谢谢你,伙计:)

标签: r shiny


【解决方案1】:

对我来说,错误是

incorrect length (0), expecting: 6132

我发现这是由于输入变量和过滤器名称不匹配造成的。我使用的输入变量都是小写的,但在 dplyr 过滤器中,第一个字母是大写的。

【讨论】:

    【解决方案2】:

    试试这个:

    library(shiny)
    library(ggplot2)
    library(dplyr)
    
    
    shinyServer(function(input, output, session) {
    
      filter1<-reactive({
        req(input$landInput, data)
    
        data%>%
          filter(Land == input$landInput)
    
      })  
    
      output$plot<-renderPlot({
        req(filter())
    
        ggplot(filter(), aes(Jahr, Rate, group=Land, colour=Land))+
        geom_line(size=.5)+geom_point()+
        theme(legend.title=element_blank())
    
        })
    })
    

    【讨论】:

    • 我认为您的代码中有一个小错字。您在renderPlot() 中引用filter(),我认为您想在req()ggplot() 中引用您的反应函数filter1()
    猜你喜欢
    • 2016-07-07
    • 2019-01-11
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 2018-05-24
    相关资源
    最近更新 更多