setting a value in the current session from a reactive

807 views
Skip to first unread message

Alex Brown

unread,
May 25, 2013, 3:41:59 AM5/25/13
to shiny-...@googlegroups.com
Local assignment in a reactive uses <-

Global assignment uses <<-

How do I set a session variable from inside a reactive?

I could use a reactiveValue, but I'm not sure I want to go down that route?

What is the session parameter to shinyServer?

Can I grab the environment of the shiny session as a variable to be passed into other functions?

-Alex

Alex Brown

unread,
May 25, 2013, 12:38:02 PM5/25/13
to shiny-...@googlegroups.com
Ah <<- I only ever used it for global a before.

Joe Cheng

unread,
May 26, 2013, 12:38:05 AM5/26/13
to shiny-...@googlegroups.com
You got it.

FYI, the session parameter is where we hang a bunch of (not yet documented?) information and functions that you might find useful; it is not for storing your own data. session$clientData contains metadata from the browser, session$sendCustomMessage/sendInputMessage/sendJavascript are used for sending various types of messages to the client, and session$onSessionEnded is used to register a callback for when the session is terminated (i.e. after the websocket closes).


On Sat, May 25, 2013 at 9:38 AM, Alex Brown <alexb...@gmail.com> wrote:
Ah <<- I only ever used it for global a before.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Brian Bolt

unread,
May 28, 2013, 11:37:41 PM5/28/13
to shiny-...@googlegroups.com
Is the session variable something that is available in the public version of Shiny Server?

Joe Cheng

unread,
May 29, 2013, 1:30:13 PM5/29/13
to shiny-...@googlegroups.com
It's a feature of Shiny, not Shiny Server, but you do need the latest version of Shiny (i.e. install it from GitHub).

if (!require('devtools'))
  install.packages('devtools')
install.packages('httpuv', repos=c(RStudio='http://rstudio.org/_packages', CRAN='http://cran.rstudio.com')
devtools::install_github('shiny', 'rstudio')

Brian Bolt

unread,
May 29, 2013, 2:24:08 PM5/29/13
to shiny-...@googlegroups.com
thank you.

Gene Leynes

unread,
Jun 14, 2013, 4:48:28 PM6/14/13
to shiny-...@googlegroups.com
FYI, 

You (R Studio) don't mention the GitHub install on the page where this is documented

I was just going to post that there's a but, but it's just that I don't have the latest version installed.  Not sure if I want the bleeding, bleeding edge version.... so I didn't upgrade to make sure that was the problem.  However the first server / ui example didn't work for me as posted.

By the way, I think you would want to have a link back to Rstudio.org and the name R Studio on your shiny documentation.

Joe Cheng

unread,
Jun 14, 2013, 5:47:26 PM6/14/13
to shiny-...@googlegroups.com
Hi Gene, thanks for the report. The version now on CRAN (0.6.0) supports session$clientData. If that's not what you're seeing, please let us know.

Thanks!

Gene Leynes

unread,
Jun 18, 2013, 11:47:10 AM6/18/13
to shiny-...@googlegroups.com
Yes, Shiny 0.6.0 did fix the session problem, but it also required me to upgrade R from 3.0.0 to 3.0.1 (which I also mentioned in a different thread that is related to that issue).

Alex Brown

unread,
Jun 21, 2013, 7:47:41 PM6/21/13
to shiny-...@googlegroups.com
Some of the documentations places 'session' in argument 3, some places something else -  'server' or perhaps 'client data' I don't recall. - what gives?

-Alex

Joe Cheng

unread,
Jun 21, 2013, 9:15:47 PM6/21/13
to shiny-...@googlegroups.com
clientData used to go there (and still can) but now we just recommend you use session and access clientData using session$clientData.
Sent from my phone

Winston Chang

unread,
Jun 22, 2013, 2:28:20 PM6/22/13
to shiny-...@googlegroups.com
On Fri, Jun 21, 2013 at 6:47 PM, Alex Brown <alexb...@gmail.com> wrote:
Some of the documentations places 'session' in argument 3, some places something else -  'server' or perhaps 'client data' I don't recall. - what gives?

-Alex


It actually doesn't matter which order you put the arguments in - when the function is called, Shiny passes named arguments to it. But as Joe mentioned, the recommendation now is to use session$clientData instead of clientData.

Reply all
Reply to author
Forward
0 new messages