不正确的尺寸数量的闪亮错误

时间:2018-04-10 01:52:53

标签: r shiny

我正在从公共页面的Facebook API中提取数据。

我的数据如下:

> str(db)
'data.frame':   3494 obs. of  13 variables:
 $ X             : int  1 2 3 4 5 6 7 8 9 10 ...
 $ from_id       : num  1.06e+14 1.06e+14 1.06e+14 1.06e+14 1.06e+14 ...
 $ from_name     : Factor w/ 4 levels "Halkbank AD Skopje",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ message       : Factor w/ 3162 levels "- Имаш иновативна идеја за бизнис? <ed><U+00A0><U+00BD><ed><U+00B4><U+00A5>\n- Ти фали грант до 10.000€? \n- Мо"| __truncated__,..: 2149 3061 2115 2751 1187 778 786 2848 2885 1748 ...
 $ created_time  : Factor w/ 3491 levels "2012-01-04T15:39:25+0000",..: 3487 3483 3482 3477 3475 3472 3471 3470 3466 3465 ...
 $ type          : Factor w/ 6 levels "event","link",..: 4 4 4 4 4 4 4 4 4 4 ...
 $ link          : Factor w/ 3111 levels "http://6.seo.com/wp-content/uploads/2011/12/How-has-the-internet-changed-education-Infographic.png",..: 1431 1429 1425 1428 1430 1423 1440 1426 1427 1424 ...
 $ id            : Factor w/ 3494 levels "106087736756825_106091843423081",..: 153 151 146 149 152 144 150 147 148 145 ...
 $ story         : Factor w/ 322 levels "Halkbank AD Skopje added 10 new photos — with Ена Поповиќ.",..: NA NA NA NA NA NA 117 NA NA 123 ...
 $ likes_count   : int  19 89 49 36 169 37 107 227 47 29 ...
 $ comments_count: int  0 0 0 5 1 0 3 57 0 0 ...
 $ shares_count  : int  3 1 2 3 7 1 10 18 12 0 ...
 $ bank          : chr  "gs" "gs" "gs" "gs" ...

根据这些数据,我想构建一个Shiny应用程序。

该应用程序应该采用单个输入 - selectInput(列库中包含的唯一级别),根据用户在应用程序的服务器部分提供的输入进行过滤,并返回一个输出facebook帖子数量的条形图给定fb页面一年。

此尝试如下:

library(shiny)
library(lubridate)
library(ggplot2)

setwd("~/r_directory")
db <- read.csv("./banks.csv")
db$bank <- as.character(db$bank)

db$date <- substr(db$created_time, 0, 10) 
db$date <- ymd(db$date)
db$year <- year(db$date)
list <- unique(db$bank)

# Use a fluid Bootstrap layout
ui <- fluidPage(    

  # Give the page a title
  titlePanel("Number of daily FB posts by bank"),

  # Generate a row with a sidebar
  sidebarLayout(      

    # Define the sidebar with one input
    sidebarPanel(
      selectInput("bank", "Bank:", 
                  choices=list),
      hr(),
      helpText("Data info...")
    ),

    # Create a spot for the barplot
    mainPanel(
      plotOutput("bankData")  
    )

  )
)

server <- function(input, output) {

  observe({

  db <- db[input$bank, "bank"]  

  test <-  data.frame(table(db[, "year"]))


  # Fill in the spot we created for a plot
  output$bankData <- renderPlot({


    p <-ggplot(test, aes(Var1, Freq)) 
    p + geom_bar(stat = "identity")



  })  })
}


shinyApp(ui = ui, server = server)

但是我收到以下错误:

Warning: Error in [: incorrect number of dimensions
Stack trace (innermost first):
61: table
60: data.frame
59: observerFunc [#7]
4: <Anonymous>
3: do.call
2: print.shiny.appobj
1: <Promise>
ERROR: [on_request_read] connection reset by peer

1 个答案:

答案 0 :(得分:1)

您最好使用observe()而不是test <- reactive({ db <- db[db$bank==input$bank, ] data.frame(table(db[, "year"])) }) output$bankData <- renderPlot({ p <-ggplot(test(), aes(Var1, Freq)) p + geom_bar(stat = "identity") })

ionic remove platform ios
ionic platforms rm ios
ionic platforms add ios
ionic run