Is it possible to get the HTTP request header data into a shiny server app?

3,299 views
Skip to first unread message

gregd...@gmail.com

unread,
Jul 18, 2013, 1:55:26 PM7/18/13
to shiny-...@googlegroups.com
Title says it all

Joe Cheng

unread,
Jul 18, 2013, 7:46:08 PM7/18/13
to shiny-...@googlegroups.com
Not yet, but we're planning to add it soon.


On Thu, Jul 18, 2013 at 10:55 AM, <gregd...@gmail.com> wrote:
Title says it all

--
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.
 
 

Stephan Holtmeier

unread,
Jul 19, 2013, 5:00:07 AM7/19/13
to shiny-...@googlegroups.com
This feature would be very interesting fur us, too!

Joe Cheng

unread,
Jul 22, 2013, 6:47:04 PM7/22/13
to shiny-...@googlegroups.com
I just checked it into the Shiny repository on GitHub. Use the instructions on the repo page to install the latest development build.

Once you have updated Shiny (and keep in mind that if you are doing this for Shiny Server, the development build of Shiny must be installed either by root or by the "shiny" user) then you can add a "session" parameter to your shinyServer function, then access session$request to get at the request. The request is an environment that matches the Rook API, so custom HTTP headers are available as HTTP_<headername>, all caps.

Example:

shinyServer(function(input, output, session) {
  print(session$request$HTTP_USER_AGENT)
})


On Fri, Jul 19, 2013 at 2:00 AM, Stephan Holtmeier <stephan....@gmail.com> wrote:
This feature would be very interesting fur us, too!

--

Greg D

unread,
Jul 23, 2013, 3:49:15 PM7/23/13
to shiny-...@googlegroups.com
Thanks for this Joe!

II installed it (note: it is on a network without access to github, so I downloaded as a zip, unzipped and installed from there, if it matters). I did this as the "shiny" user.

I tried opening a previously-working app (just one of the sample ones) in shiny server and it crashed. There was nothing in the log folder that I could see. When I checked just using runApp with shiny, I got a message:

Error in envRefInferField(x, what, getClass(class(x)), selfEnv):
'request' is not a valid field or method name for reference class "WebSocket"

Thanks,
Greg



--
You received this message because you are subscribed to a topic in the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shiny-discuss/zajV1HsstYc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to shiny-discus...@googlegroups.com.

Joe Cheng

unread,
Jul 23, 2013, 4:34:54 PM7/23/13
to shiny-...@googlegroups.com
I think your version of the httpuv R package might be out of date. The version on CRAN should be recent enough.

Greg D

unread,
Jul 23, 2013, 5:03:04 PM7/23/13
to shiny-...@googlegroups.com
Thanks. I have 1.0.5 so I'll update and give it a shot.

Greg D

unread,
Jul 31, 2013, 10:27:48 AM7/31/13
to shiny-...@googlegroups.com
Hi Joe,

So I think my original question was a bit inaccurate. I'm looking not just for the HTTP request info but all headers (e.g. user-agent, accept-language, accept-encoding) etc. Is this possible?

Thanks,
Greg



Joe Cheng

unread,
Jul 31, 2013, 4:04:04 PM7/31/13
to shiny-...@googlegroups.com
The very latest versions of httpuv and shiny on GitHub support this. See the instructions in this message:

You would look at session$request$HTTP_USER_AGENT, session$request$HTTP_ACCEPT_LANGUAGE, etc.
Message has been deleted
Message has been deleted

Greg D

unread,
Aug 6, 2013, 4:47:15 PM8/6/13
to shiny-...@googlegroups.com
Thanks. Tried it out and am making some progress.

The new headers are only available when I run as a standalone app (i.e. runApp() in R) as opposed to viewing it in shiny server. I noticed your comment about Shiny Server, and to confirm, this update was done by the "rshiny" user and the server/R libraries are installed in his home directory.

If it easier, I'm happy to discuss outside the group.

Scott Stern

unread,
Aug 9, 2013, 3:19:37 PM8/9/13
to shiny-...@googlegroups.com
I too cannot get it to work, running on the newest shiny server and shiny package (both straight from the repo).  They were installed/are running as root.

Scott Stern

unread,
Aug 9, 2013, 3:42:09 PM8/9/13
to shiny-...@googlegroups.com
Nevermind, it works!  Well I am getting the session$request variables anyways.  Does QUERY_STRING not yet work?  I try just passing something like server:3838/user/app/?test=5 and nothing appears in the QUERY_STRING.

Winston Chang

unread,
Aug 9, 2013, 3:46:38 PM8/9/13
to shiny-...@googlegroups.com


--

Scott Stern

unread,
Aug 9, 2013, 4:21:22 PM8/9/13
to shiny-...@googlegroups.com
Thanks!  I don't know how I missed that.  That seems to work "fine" in terms of wanting to pass parameters that aren't part of your inputs, but I am still confused as to whether there is a planned solution to actually have the URL change with the inputs, similar to what has been brought up in this thread: https://groups.google.com/forum/#!topic/shiny-discuss/8ZpNyzPKaTg.  

The session variable as it stands is only accessible on the server.R side, and does not make the browser URL react.  I understand the fear of globals (like the PHP $_REQUEST), but at least to be able to share an app in a precise/preloaded state, it would be super useful.

For now my firm is considering wrapping Alex Brown's JavaScript implementation, but obviously we would rather not maintain our own (forked) infrastructure if possible.

Greg D

unread,
Aug 12, 2013, 10:28:24 AM8/12/13
to shiny-...@googlegroups.com
Scott, when you said you're getting it to work, are you getting all of the HTTP headers (e.g. user agent, accept-encoding) that one would expect? I am getting some on shiny server, but not most of the ones I would expect (and ones that I'm seeing with just shiny).

In general, what might cause differences between shiny and shiny server? 


--

Greg D

unread,
Aug 30, 2013, 3:34:57 PM8/30/13
to shiny-...@googlegroups.com
Just following up on this... still having issues - only seeing full list of headers with shiny/runApp and not shiny server. Might I need to update shiny server (it's a bit old, a few months....)


On Tuesday, August 6, 2013 4:47:15 PM UTC-4, Greg D wrote:

Greg D

unread,
Sep 6, 2013, 10:14:32 PM9/6/13
to shiny-...@googlegroups.com
So the NEWS description makes things clearer:

Note: When running in a Shiny Server environment, the request will reflect
  the proxy HTTP request that was made from the Shiny Server process to the R
  process, not the request that was made from the web browser to Shiny Server.

So is there any way to get what the request the browser made to shiny server?

Joe Cheng

unread,
Sep 8, 2013, 3:56:59 AM9/8/13
to shiny-...@googlegroups.com
Which headers are you not seeing? I think I might know how to fix this.


--

Greg D

unread,
Sep 8, 2013, 8:07:02 PM9/8/13
to shiny-...@googlegroups.com
I am missing the ones below. There are also some additional headers I'm creating and forwarding with Apache. However, the results below are also what I see from a new vanilla install of shiny server and shiny right out of the box.

Only seen via shiny runApp and not shiny server:

HTTP_ACCEPT
HTTP_ACCEPT_ENCODING
HTTP_ACCEPT_LANGUAGE
HTTP_CACHE_CONTROL
HTTP_ORIGIN
HTTP_PRAGMA
HTTP_USER_AGENT

In both:
HTTP_CONNECTION HTTP_HOST HTTP_SEC_WEBSOCKET_KEY
HTTP_SEC_WEBSOCKET_VERSION HTTP_UPGRADE httpuv.version PATH_INFO QUERY_STRING REMOTE_ADDR REMOTE_PORT REQUEST_METHOD rook.errors rook.input rook.url_scheme rook.version SCRIPT_NAME SERVER_NAME SERVER_PORT


--
You received this message because you are subscribed to a topic in the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shiny-discuss/zajV1HsstYc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to shiny-discus...@googlegroups.com.

crazyman sam

unread,
Oct 3, 2013, 6:29:12 PM10/3/13
to shiny-...@googlegroups.com
Hi everyone,

Has there been resolution on this issue? I am experiencing the exact same issue as Greg with reference to the missing headers. I looked into the code and it seems you can add a custom request handler in main.js to inspect the headers but this requires coding in js and is less than ideal. When I put a function there to console.log the req, I see the desired headers but not from my server.R code.

Thank you!

VIGNESH PRAJAPATI

unread,
Jul 19, 2014, 6:54:35 PM7/19/14
to shiny-...@googlegroups.com
Hi Winston Chang, 

Thanks for your answer. I tried and get it solved. Thanks a ton.!!
Reply all
Reply to author
Forward
0 new messages