glouton
glouton copied to clipboard
'JS-cookies' in Shiny
glouton
The goal of glouton is to handle browser cookies in shiny.
It's built on top of js-cookie.
Installation
You can install the released version of glouton from github with:
remotes::install_github("ColinFay/glouton")
Function reference
In the UI, add use_glouton() to integrate {glouton} to your app.
In the server, you can use:
add_cookieto add a session cookie. Takes a name, content, and thesessionobject.fetch_cookies/fetch_cookieto get all or one cookie. Takes thesessionandinputobjects and a name forfetch_cookie()remove_cookieto remove one cookie. Takes a name of a cookie and thesessionobject.
Example
This is a basic example which shows you how to solve a common problem:
library(glouton)
library(shiny)
ui <- function(request){
tagList(
use_glouton(),
textInput("cookie_name", "cookie name"),
textInput("cookie_content", "cookie content"),
actionButton("setcookie", "Add cookie"),
actionButton("getcookie", "get cookie"),
verbatimTextOutput("cook"),
verbatimTextOutput("one")
)
}
server <- function(input, output){
r <- reactiveValues()
observeEvent( input$setcookie , {
add_cookie(input$cookie_name, input$cookie_content)
})
observeEvent( input$getcookie , {
r$cook <- fetch_cookies()
})
output$cook <- renderPrint({
r$cook
})
}
shinyApp(ui, server)
TO DO
- Support passing domain / path / expire to cookie https://github.com/js-cookie/js-cookie#basic-usage