Using shiny app's webserver to serve data files for my widget's javascript code?

shiny

#1

Two shiny widgets I work on benefit from being able to load data files in javascript. The nice capabilities of customMessageHandlers don't always work for this. (For instance, igv.js, the integrative genomics viewer, displays a genome track from a web-served url. Sometimes we create those tracks on the fly, save them locally from app.R, then send a message to our widget's javascript, and ask igv to display the url.

In related projects where I usehttpuv but not shiny, I find that this works reliably:

var dataURI = window.location.href + "?" + bedFileName;

creates a URI which can be used in Javascript. The requested file is returned by httpuv's simple built-in web server. When I try this with shiny, dataURI redirects to return the app itself, lopping off the "?" and the appended filename.

Any advice? Can I use the built-in webserver to serve up local files to my widget javascript?

Thank you,

  • Paul

#2

The answer turned out to be simple:

addResourcePath("tracks", "tracks")

enables http GET via the shiny webserver, to window.location.href + "/tracks/" + filename.


#3

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: