-
Notifications
You must be signed in to change notification settings - Fork 0
/
shinytest
81 lines (59 loc) · 2.26 KB
/
shinytest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
options(googleAuthR.webapp.client_id = "clientid.apps.googleusercontent.com")
options(googleAuthR.webapp.client_secret = "secrect")
options(googleAuthR.redirect = "https://thinkuser.shinyapps.io")
library(shiny)
gar_set_client(scopes = c("https://www.googleapis.com/auth/analytics.readonly"))
library(googleAuthR)
library(googleAnalyticsR)
#gar_set_client(web_json = "shiny_auth_web_client.json",
# scopes="https://www.googleapis.com/auth/analytics.readonly"
# )
#-- we enabled local host port 1221 on google console here
#--https://console.cloud.google.com/apis/credentials/oauthclient/39354250887-qrk2hb0gnajvkjpg7eou5jluf51vvac7.apps.googleusercontent.com?project=stellar-vista-149518
#options(shiny.port=1221)
# Define UI for application that draws a histogram
ui <- fluidPage(
#-- set the button without functionality just UI
googleAuth_jsUI("auth"),
#interface
column(width=12, authDropdownUI("auth_dropdown",
inColumns = TRUE)),
dateRangeInput("datepicker", NULL, start = Sys.Date() - 300),
plotOutput("trend_plot")
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
#-- Get the auth token
auth <- callModule(googleAuth_js, "auth")
#-- Get GA account lists
ga_accounts <- reactive({
req(auth())
with_shiny(
ga_account_list,
shiny_access_token = auth()
)
})
view_id <- callModule(authDropdown, "auth_dropdown",
ga.table = ga_accounts)
ga_data <- reactive({
#require viewid and date to be present
req(view_id())
req(input$datepicker)
with_shiny(
google_analytics,
view_id(),
date_range=input$datepicker,
dimensions="date",
metrics="sessions",
max=-1,
shiny_access_token = auth() ##every with shiny function need this shiny access token as well
)
})
output$trend_plot <- renderPlot({
req(ga_data())
ga_data <- ga_data()
plot(ga_data$sessions, type="l")
})
}
# Run the application
shinyApp(ui = ui, server = server)