Skip to content

Commit

Permalink
Adding cookie banner code and script
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbielby committed Jun 7, 2024
1 parent fe7387e commit 536289d
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 41 deletions.
2 changes: 2 additions & 0 deletions global.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ fiveyag_cohort_year <- "2014/15"

# tidy_code_function -------------------------------------------------------------------------------

google_analytics_key <- "Q08W0Y4G5C"

tidy_code_function <- function() {
message("----------------------------------------")
message("App scripts")
Expand Down
66 changes: 33 additions & 33 deletions renv.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"R": {
"Version": "4.3.3",
"Version": "4.4.0",
"Repositories": [
{
"Name": "CRAN",
Expand All @@ -25,14 +25,14 @@
},
"DBI": {
"Package": "DBI",
"Version": "1.2.2",
"Version": "1.2.3",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"methods"
],
"Hash": "164809cd72e1d5160b4cb3aa57f510fe"
"Hash": "065ae649b05f1ff66bb0c793107508f5"
},
"DT": {
"Package": "DT",
Expand Down Expand Up @@ -107,7 +107,7 @@
},
"Hmisc": {
"Package": "Hmisc",
"Version": "5.1-2",
"Version": "5.1-3",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
Expand All @@ -131,7 +131,7 @@
"rpart",
"viridis"
],
"Hash": "c0d441bec5693f2cad30231f7f72d90a"
"Hash": "9a446aea30bff7e8ee20f4c0973e8851"
},
"KernSmooth": {
"Package": "KernSmooth",
Expand All @@ -146,7 +146,7 @@
},
"MASS": {
"Package": "MASS",
"Version": "7.3-60.0.1",
"Version": "7.3-60.2",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
Expand All @@ -157,11 +157,11 @@
"stats",
"utils"
],
"Hash": "b765b28387acc8ec9e9c1530713cb19c"
"Hash": "2f342c46163b0b54d7b64d1f798e2c78"
},
"Matrix": {
"Package": "Matrix",
"Version": "1.6-5",
"Version": "1.7-0",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
Expand All @@ -174,7 +174,7 @@
"stats",
"utils"
],
"Hash": "8c7115cd3a0e048bda2a7cd110549f7a"
"Hash": "1920b2f11133b12350024297d8a4ff4a"
},
"R.cache": {
"Package": "R.cache",
Expand Down Expand Up @@ -297,13 +297,13 @@
},
"backports": {
"Package": "backports",
"Version": "1.4.1",
"Version": "1.5.0",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R"
],
"Hash": "c39fbec8a30d23e721980b8afb31984c"
"Hash": "e1e1b9d75c37401117b636b7ae50827a"
},
"base64enc": {
"Package": "base64enc",
Expand Down Expand Up @@ -392,14 +392,14 @@
},
"cachem": {
"Package": "cachem",
"Version": "1.0.8",
"Version": "1.1.0",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"fastmap",
"rlang"
],
"Hash": "c35768291560ce302c0a6589f92e837d"
"Hash": "cd9a672193789068eb5a2aad65a0dedf"
},
"callr": {
"Package": "callr",
Expand Down Expand Up @@ -631,7 +631,7 @@
"RemoteUsername": "dfe-analytical-services",
"RemoteRepo": "dfeshiny",
"RemoteRef": "main",
"RemoteSha": "fb0a97efd819c4735c3e57dc3b294a5ad2911ef5",
"RemoteSha": "6a4c898934274a5f6f13188c379d04667c4cf1c9",
"Requirements": [
"RCurl",
"checkmate",
Expand All @@ -643,7 +643,7 @@
"stringr",
"styler"
],
"Hash": "23cba66872a9f50b6cde614c29286073"
"Hash": "dabb4b32305d045b5e091bc0dcb77988"
},
"diffobj": {
"Package": "diffobj",
Expand Down Expand Up @@ -753,10 +753,10 @@
},
"fastmap": {
"Package": "fastmap",
"Version": "1.1.1",
"Version": "1.2.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "f7736a18de97dea803bde0a2daaafb27"
"Hash": "aa5e1cd11c2d15497494c5292d7ffcc8"
},
"fontawesome": {
"Package": "fontawesome",
Expand Down Expand Up @@ -896,14 +896,14 @@
},
"highr": {
"Package": "highr",
"Version": "0.10",
"Version": "0.11",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"xfun"
],
"Hash": "06230136b2d2b9ba5805e1963fa6e890"
"Hash": "d65ba49117ca223614f71b60d85b8ab7"
},
"hms": {
"Package": "hms",
Expand Down Expand Up @@ -1054,7 +1054,7 @@
},
"knitr": {
"Package": "knitr",
"Version": "1.46",
"Version": "1.47",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
Expand All @@ -1066,7 +1066,7 @@
"xfun",
"yaml"
],
"Hash": "6e008ab1d696a5283c79765fa7b56b47"
"Hash": "7c99b2d55584b982717fcc0950378612"
},
"labeling": {
"Package": "labeling",
Expand Down Expand Up @@ -1260,14 +1260,14 @@
},
"mvtnorm": {
"Package": "mvtnorm",
"Version": "1.2-4",
"Version": "1.2-5",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"stats"
],
"Hash": "17e96668f44a28aef0981d9e17c49b59"
"Hash": "4d1891e59ac7a12b4e7e8a69349125f1"
},
"networkD3": {
"Package": "networkD3",
Expand Down Expand Up @@ -1310,13 +1310,13 @@
},
"openssl": {
"Package": "openssl",
"Version": "2.1.2",
"Version": "2.2.0",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"askpass"
],
"Hash": "ea2475b073243d9d338aa8f086ce973e"
"Hash": "2bcca3848e4734eb3b16103bc9aa4b8e"
},
"openxlsx": {
"Package": "openxlsx",
Expand Down Expand Up @@ -1695,18 +1695,18 @@
},
"rlang": {
"Package": "rlang",
"Version": "1.1.3",
"Version": "1.1.4",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"utils"
],
"Hash": "42548638fae05fd9a9b5f3f437fbbbe2"
"Hash": "3eec01f8b1dee337674b2e34ab1f9bc1"
},
"rmarkdown": {
"Package": "rmarkdown",
"Version": "2.26",
"Version": "2.27",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
Expand All @@ -1725,7 +1725,7 @@
"xfun",
"yaml"
],
"Hash": "9b148e7f95d33aac01f31282d49e4f44"
"Hash": "27f9502e1cdbfa195f94e03b0f517484"
},
"rootSolve": {
"Package": "rootSolve",
Expand Down Expand Up @@ -2066,15 +2066,15 @@
},
"terra": {
"Package": "terra",
"Version": "1.7-71",
"Version": "1.7-78",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"Rcpp",
"methods"
],
"Hash": "e8611881ab70a4fb7a1f629b31e6fcff"
"Hash": "8f020def0792119cb98bd8f696dab22d"
},
"testthat": {
"Package": "testthat",
Expand Down Expand Up @@ -2323,15 +2323,15 @@
},
"xfun": {
"Package": "xfun",
"Version": "0.43",
"Version": "0.44",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"grDevices",
"stats",
"tools"
],
"Hash": "ab6371d8653ce5f2f9290f4ec7b42a8e"
"Hash": "317a0538d32f4a009658bcedb7923f4b"
},
"xtable": {
"Package": "xtable",
Expand Down
9 changes: 9 additions & 0 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ server <- function(input, output, session) {

session$onSessionEnded(stopApp) # commenting out to test using lighthouse


output$cookie_status <- cookie_banner_server(
"cookie-banner",
input_cookies = shiny::reactive(input$cookies),
parent_session = session,
google_analytics_key = google_analytics_key,
cookie_link_panel = "cookies_panel_ui"
)

# Links to tabs --------------------------------------------

observeEvent(input$link_to_industryFlow_tab, {
Expand Down
23 changes: 15 additions & 8 deletions ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@ fluidPage(

# This CSS sets the 7th item on the navbar to the right
tagList(
tags$head(tags$style(HTML("
.navbar-nav {
float: none !important;
}
.navbar-nav > li:nth-child(9) {
float: right;
}
")))
tags$head(
tags$style(
HTML(".navbar-nav {
float: none !important;
}
.navbar-nav > li:nth-child(9) {
float: right;
}")
)
)
),
cookie_banner_ui(
"cookie-banner",
"Your dashboard name"
),
navbarPage("",
id = "navbar",
tags$head(includeHTML(("google-analytics.html"))),
dfe_cookie_script(),
shinyGovstyle::banner(
"beta banner",
"beta",
Expand Down
26 changes: 26 additions & 0 deletions www/cookie-consent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function getCookies(){
var res = Cookies.get();
Shiny.setInputValue('cookies', res);
}

Shiny.addCustomMessageHandler('cookie-set', function(msg){
Cookies.set(msg.name, msg.value);
getCookies();
})

Shiny.addCustomMessageHandler('cookie-remove', function(msg){
Cookies.remove(msg.name);
getCookies();
})

$(document).on('shiny:connected', function(ev){
getCookies();
})

Shiny.addCustomMessageHandler('analytics-consent', function(msg){
gtag('consent', 'update', {
'analytics_storage': msg.value
});
})


0 comments on commit 536289d

Please sign in to comment.