I have a shiny app (using shiny dashboard). I am trying to pass in parameters on the url, use these to produce some data and then return it to the calling application. I put this in my server:
observe({
#all url params come in via the 'url_search' variable.
query <- parseQueryString(session$clientData$url_search)
action <- query[['action']]
if (!is.null(action)) {
#handle all supported request here
if(action == 'blah') {
#... do somework here to create my dataframe
shiny:::httpResponse(status=200, content_type="text/html; charset=UTF-8", mydataframe)
} else {
#... ignore unrecognized request
}
}
})
This works, but not in the intended way:
The request is processed correctly, but the first thing that happens is the entire shiny app is rendered. Then, later on, I see a 'POST' request, with my original url as a referrer, and this posts the needed data as JSON data, but I don't know where it goes.
What do I need so that I can send my url (with params) to my shiny app, and then have it bypass its usual interactive mode and just return raw json data immediately without rendering html? Is it because I am making the request via a browser? Should I make the same url request programmatically in R?
update: I tried using fromJSON('...') on my url doesn't work, either. I get:
Error in fromJSON(content, handler, default.size, depth, allowComments, :
invalid JSON input
I don't believe you can do that using just Shiny. There are, however, some options to have R behave like an API and return JSON responses. See: http://plumber.trestletech.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With