Google Analytics integration into Shiny Dashboard

109 views
Skip to first unread message

Conal Monaghan

unread,
Dec 28, 2016, 8:41:11 PM12/28/16
to Shiny - Web Framework for R
Hi,
     I was wondering how to integrate Google analytics into a shiny Dashboard page. Normally you would create the .js file from Google analytics (write in text editor and export as google-analytics.js) as below:

     shinyUI(fluidPage( tags$head(includeScript("google-analytics.js")), 
                                    titlePanel("Sunlight in the US")
                                 )
                  )


When using shiny dashboard it produces sourcing errors. I have tried in both locations indicated below and both produced errors. Is there a different process for integrating analytics when using Dashboard?

shinyUI(                                                                                         #### Location 1
  dashboardPage(                                                                          #### Location 2
                dashboardHeader(title = "Sunlight in the US")
                           )
          )


    Thanks in advance,
                                   Conal 





     

Aline Deschamps

unread,
Dec 29, 2016, 5:47:57 AM12/29/16
to Shiny - Web Framework for R
Hi,

I don't know if it's the "right" location but I've put the call to the js file in the dashboardBody (in the "ui.R" file) and it works fine :

shinyUI <- dashboardPage(

          dashboardSidebar
( ... ),

          dashboardBody
(

                    tags$head
(includeScript("./www/js/google-analytics.js")),

                    tabItems
( ... )

         
)

)


HTH ! :)


Best regards.

Conal Monaghan

unread,
Dec 31, 2016, 2:26:08 AM12/31/16
to Shiny - Web Framework for R
Hi Aline,
           Your solution worked perfectly! Thank you very much for your help.

  Kind Regards,
        Conal 
Reply all
Reply to author
Forward
0 new messages