Giter VIP home page Giter VIP logo

glouton's Introduction

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

glouton's People

Contributors

colinfay avatar davidbarke avatar johncoene avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

glouton's Issues

Problem with remove_cookie() ?

Hello Colin,
Thanks for this very useful package ! I am not at all expert in cookie management and javascript but if I can use it to retain user session in association with the shinymanager package it would be wonderful :).
I have noticed a problem with the way I try to use the remove_cookie() function, cf below your example modified to add a button to remove all cookies:

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"),
    actionButton("rmcookies", "remove cookie(s)"),
    verbatimTextOutput("cook"),
    verbatimTextOutput("one")
  )
}

server <- function(input, output, session){
  
  r <- reactiveValues()
  
  observeEvent( input$setcookie , {
    add_cookie(input$cookie_name, input$cookie_content)
  })
  observeEvent( input$getcookie , {
    r$cook <- fetch_cookies()
  })
  observeEvent(input$rmcookies , {
    cookienames <- names(r$cook)
    for(cname in cookienames){
      remove_cookie(cname)
    }
  })
  output$cook <- renderPrint({
    r$cook
  })
}

shinyApp(ui, server)

It seems that I can't remove the cookies with the function remove_ccokies(). Is it a bug or a misuse of the function in the example above ?

Best regards,
Jonas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.