r - How to access browser session/cookies from within Shiny App -
how can access cookies , other browser-related session data within shiny app?
with session$clientdata, able other client details host,port,query param...
is there other way cookies in shiny app?
to build on great comments, can use js.cookie.js package shiny.oninputchange() function return cookies.
an example app here: https://beta.rstudioconnect.com/iwallace/cookies/
--ui.r--
library(shiny) library(shinydashboard) fluidpage( tags$head(tags$script(src="js.cookie.js")), # shiny element display unformatted text box(title ="click gray square view cookies!", verbatimtextoutput("results"),actionbutton("go","click me")), # javascript code send data shiny server tags$script(' document.getelementbyid("go").onclick = function() { var number = math.random(); cookies.set(\'name\', \'value\', { expires: 7 }); cookies.set(\'cookie_2\', \'value\', { expires: 7 }); var my_cookie = cookies.get(); shiny.oninputchange("mydata", my_cookie); }; ')
)
--server.r--
library(shiny) shinyserver(function(input, output,session) { output$results = renderprint({ input$mydata }) })
Comments
Post a Comment