Skip to content
'JS-cookies' in Shiny
JavaScript R
Branch: master
Clone or download
Latest commit 75363f6 Nov 25, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R session defaults to + remove need to pass Nov 23, 2019
inst
man session defaults to + remove need to pass Nov 23, 2019
DESCRIPTION
LICENSE
LICENSE.md 👶 Sep 17, 2019
NAMESPACE
README.Rmd session defaults to + remove need to pass Nov 23, 2019
README.html session defaults to + remove need to pass Nov 23, 2019
README.md
glouton.Rproj

README.md

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_cookie to add a session cookie. Takes a name, content, and the session object.
  • fetch_cookies / fetch_cookie to get all or one cookie. Takes the session and input objects and a name for fetch_cookie()
  • remove_cookie to remove one cookie. Takes a name of a cookie and the session object.

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

You can’t perform that action at this time.