Skip to content

Commit

Permalink
Set up cookies to save user's language selection
Browse files Browse the repository at this point in the history
  • Loading branch information
stesiam committed Apr 22, 2024
1 parent 0040dc7 commit f657ced
Show file tree
Hide file tree
Showing 3 changed files with 926 additions and 1 deletion.
28 changes: 27 additions & 1 deletion app/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ library(shiny)
library(shiny.tailwind)
library(shiny.i18n)
library(dplyr)
library(cookies)

source("global.R")

Expand All @@ -12,7 +13,8 @@ i18n$set_translation_language("en")
# options(shiny.launch.browser = .rs.invokeShinyWindowExternal)

# Define UI for application that draws a histogram using HTML divs and tailwind
ui <- div(
ui <- add_cookie_handlers(
div(
tags$head(
tags$meta(name = "viewport",
content="width=device-width, initial-scale = 1"),
Expand Down Expand Up @@ -191,8 +193,32 @@ ui <- div(
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {

## Set cookies to remember language selection

observeEvent(
input$selected_language,
{
set_cookie(
cookie_name = "lang_cookie",
cookie_value = input$selected_language
)
}
)

observeEvent(
get_cookie("lang_cookie"),
updateSliderInput(
inputId = "selected_language",
value = get_cookie("lang_cookie")
),
once = TRUE
)

## End of cookies

default_selected <- reactiveVal("propbonus")

Expand Down
155 changes: 155 additions & 0 deletions app/renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
]
},
"Packages": {
"PKI": {
"Package": "PKI",
"Version": "0.1-12",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"base64enc"
],
"Hash": "999d7960fe5a5fd98267d0b68fd10065"
},
"R6": {
"Package": "R6",
"Version": "2.5.1",
Expand All @@ -30,6 +41,16 @@
],
"Hash": "5ea2700d21e038ace58269ecdbeb9ec0"
},
"askpass": {
"Package": "askpass",
"Version": "1.2.0",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"sys"
],
"Hash": "cad6cf7f1d5f6e906700b9d3e718c796"
},
"base64enc": {
"Package": "base64enc",
"Version": "0.1-3",
Expand Down Expand Up @@ -84,13 +105,59 @@
],
"Hash": "1216ac65ac55ec0058a6f75d7ca0fd52"
},
"clock": {
"Package": "clock",
"Version": "0.7.0",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"cli",
"cpp11",
"lifecycle",
"rlang",
"tzdb",
"vctrs"
],
"Hash": "3d8a84cdf9f6f8564531c49b70f3833d"
},
"commonmark": {
"Package": "commonmark",
"Version": "1.9.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "5d8225445acb167abf7797de48b2ee3c"
},
"cookies": {
"Package": "cookies",
"Version": "0.2.3",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"cli",
"clock",
"glue",
"htmltools",
"httpuv",
"jsonlite",
"purrr",
"rlang",
"shiny",
"stats",
"vctrs"
],
"Hash": "ec07bfdaeb45d6ab53b51d99c3dd3131"
},
"cpp11": {
"Package": "cpp11",
"Version": "0.4.7",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R"
],
"Hash": "5a295d7d963cc5035284dcdbaf334f4e"
},
"crayon": {
"Package": "crayon",
"Version": "1.5.2",
Expand All @@ -103,6 +170,16 @@
],
"Hash": "e8a1e41acf02548751f45c718d55aa6a"
},
"curl": {
"Package": "curl",
"Version": "5.2.1",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R"
],
"Hash": "411ca2c03b1ce5f548345d2fc2685f7a"
},
"digest": {
"Package": "digest",
"Version": "0.6.35",
Expand Down Expand Up @@ -307,6 +384,28 @@
],
"Hash": "18e9c28c1d3ca1560ce30658b22ce104"
},
"openssl": {
"Package": "openssl",
"Version": "2.1.2",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"askpass"
],
"Hash": "ea2475b073243d9d338aa8f086ce973e"
},
"packrat": {
"Package": "packrat",
"Version": "0.9.2",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"tools",
"utils"
],
"Hash": "55ddd2d4a1959535f18393478b0c14a6"
},
"pillar": {
"Package": "pillar",
"Version": "1.9.0",
Expand Down Expand Up @@ -350,6 +449,21 @@
],
"Hash": "434cd5388a3979e74be5c219bcd6e77d"
},
"purrr": {
"Package": "purrr",
"Version": "1.0.2",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"cli",
"lifecycle",
"magrittr",
"rlang",
"vctrs"
],
"Hash": "1cba04a4e9414bdefc9dcaa99649a8dc"
},
"rappdirs": {
"Package": "rappdirs",
"Version": "0.3.3",
Expand Down Expand Up @@ -381,6 +495,29 @@
],
"Hash": "42548638fae05fd9a9b5f3f437fbbbe2"
},
"rsconnect": {
"Package": "rsconnect",
"Version": "1.2.2",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"PKI",
"R",
"cli",
"curl",
"digest",
"jsonlite",
"lifecycle",
"openssl",
"packrat",
"renv",
"rlang",
"rstudioapi",
"tools",
"yaml"
],
"Hash": "77e9ed1307e84cd7ca1c7fb2cd7bbfe2"
},
"rstudioapi": {
"Package": "rstudioapi",
"Version": "0.16.0",
Expand Down Expand Up @@ -506,6 +643,13 @@
],
"Hash": "960e2ae9e09656611e0b8214ad543207"
},
"sys": {
"Package": "sys",
"Version": "3.4.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "3a1be13d68d47a8cd0bfd74739ca1555"
},
"tibble": {
"Package": "tibble",
"Version": "3.2.1",
Expand Down Expand Up @@ -541,6 +685,17 @@
],
"Hash": "829f27b9c4919c16b593794a6344d6c0"
},
"tzdb": {
"Package": "tzdb",
"Version": "0.4.0",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"cpp11"
],
"Hash": "f561504ec2897f4d46f0c7657e488ae1"
},
"utf8": {
"Package": "utf8",
"Version": "1.2.4",
Expand Down
Loading

0 comments on commit f657ced

Please sign in to comment.