"Error in f: Invalid dimension or metric:" 然后在 shiny 中使用 googleAnalyticsR 对数据进行批处理
"Error in f: Invalid dimension or metric:" then batching data with googleAnalyticsR in shiny
我必须构建一个 Shiny-Board,我需要从 Google 分析报告 API 中获取超过 10k 行。为此,我使用自己的 Google API-Project
在 RStudio 中执行此操作非常有效,我可以获得尽可能多的行。如果我在 shiny 中执行此操作,我不会遇到少于 10k 行的问题,如果我想获得更多行,我会收到以下错误:
2017-08-17 14:12:55> Fetched: landingPagePath city date sourceMedium sessions newUsers bounceRate pageviewsPerSession avgSessionDuration transactions transactionRevenue. [10000] total results out of a possible [190119], Start-Index: 1
2017-08-17 14:12:55> Batching data into [20] calls.
Request #: 1 : 10001 : 20001 : 30001 : 40001 : 50001 : 60001 : 70001 : 80001 : 90001
2017-08-17 14:12:57> Request to profileId: ()
Warning: Error in f: Invalid dimension or metric:
Stack trace (innermost first):
114: f
113: FUN
112: lapply
111: googleAuthR::gar_batch
110: FUN
109: lapply
108: googleAuthR::gar_batch_walk
107: batchData
106: loop_ids
105: f
104: with_shiny
103: eventReactiveHandler [#405]
83: gadata
82: renderDataTable [#511]
81: func
80: origRenderFunc
79: output$Con_Table
4: <Anonymous>
3: do.call
2: print.shiny.appobj
1: <Promise>
我可以在不同的时间范围内调用相同的查询(以免达到 10k 限制)并且它适用于维度和指标。
这是我使用的查询:
授权
options("googleAuthR.webapp.client_id" = app_config$gaClientId)
options("googleAuthR.webapp.client_secret" = app_config$gaClientSecret)
options("googleAuthR.scopes.selected" =c("https://www.googleapis.com/auth/analytics.readonly"))
## Get auth code from return URL
token <- callModule(googleAuth, "login")
ga_accounts <- reactive({
req(token())
with_shiny(ga_account_list, shiny_access_token = token())
})
selected_id <- callModule(authDropdown, "auth_menu", ga.table = ga_accounts)
查询数据
ga<-with_shiny(google_analytics,
id = gaid,
start=(as.character(input$datestart)), end=(as.character(input$dateend)),
metrics = metric,
dimensions = dime,max=99999999,
shiny_access_token = token())
更多信息:
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
> packageVersion("googleAnalyticsR")
[1] ‘0.4.1’
有人知道我错过了什么吗?
感谢 Mark Edmondson,问题已解决。不要使用 API 的 V3 版本,只需使用 V4 版本。调用看起来像这样:
ga<-with_shiny(google_analytics_4,
id = gaid,
date_range = c(as.character(input$datestart), as.character(input$dateend)),
metrics = metric,
dimensions = dime,anti_sample = TRUE,
shiny_access_token = token())
我必须构建一个 Shiny-Board,我需要从 Google 分析报告 API 中获取超过 10k 行。为此,我使用自己的 Google API-Project 在 RStudio 中执行此操作非常有效,我可以获得尽可能多的行。如果我在 shiny 中执行此操作,我不会遇到少于 10k 行的问题,如果我想获得更多行,我会收到以下错误:
2017-08-17 14:12:55> Fetched: landingPagePath city date sourceMedium sessions newUsers bounceRate pageviewsPerSession avgSessionDuration transactions transactionRevenue. [10000] total results out of a possible [190119], Start-Index: 1
2017-08-17 14:12:55> Batching data into [20] calls.
Request #: 1 : 10001 : 20001 : 30001 : 40001 : 50001 : 60001 : 70001 : 80001 : 90001
2017-08-17 14:12:57> Request to profileId: ()
Warning: Error in f: Invalid dimension or metric:
Stack trace (innermost first):
114: f
113: FUN
112: lapply
111: googleAuthR::gar_batch
110: FUN
109: lapply
108: googleAuthR::gar_batch_walk
107: batchData
106: loop_ids
105: f
104: with_shiny
103: eventReactiveHandler [#405]
83: gadata
82: renderDataTable [#511]
81: func
80: origRenderFunc
79: output$Con_Table
4: <Anonymous>
3: do.call
2: print.shiny.appobj
1: <Promise>
我可以在不同的时间范围内调用相同的查询(以免达到 10k 限制)并且它适用于维度和指标。
这是我使用的查询:
授权
options("googleAuthR.webapp.client_id" = app_config$gaClientId)
options("googleAuthR.webapp.client_secret" = app_config$gaClientSecret)
options("googleAuthR.scopes.selected" =c("https://www.googleapis.com/auth/analytics.readonly"))
## Get auth code from return URL
token <- callModule(googleAuth, "login")
ga_accounts <- reactive({
req(token())
with_shiny(ga_account_list, shiny_access_token = token())
})
selected_id <- callModule(authDropdown, "auth_menu", ga.table = ga_accounts)
查询数据
ga<-with_shiny(google_analytics,
id = gaid,
start=(as.character(input$datestart)), end=(as.character(input$dateend)),
metrics = metric,
dimensions = dime,max=99999999,
shiny_access_token = token())
更多信息:
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
> packageVersion("googleAnalyticsR")
[1] ‘0.4.1’
有人知道我错过了什么吗?
感谢 Mark Edmondson,问题已解决。不要使用 API 的 V3 版本,只需使用 V4 版本。调用看起来像这样:
ga<-with_shiny(google_analytics_4,
id = gaid,
date_range = c(as.character(input$datestart), as.character(input$dateend)),
metrics = metric,
dimensions = dime,anti_sample = TRUE,
shiny_access_token = token())