Reputation: 301
I have a simple python program, which should push its data into an R Shiny application. These lines in Shiny parse the "GET" input:
# Parse the GET query string
output$queryText <- renderText({
query <- parseQueryString(session$clientData$url_search)
eventList[query$eventid] <<- query$event
})
This works fine with a browser calling "http://127.0.0.1:5923/?eventid=1223&event=somestring". If I try to call the URL in python I get a "Connection reset by peer" in R and nothing is added to the list. My Python code so far:
request = urllib2.Request("http://127.0.0.1:5923/?eventid=1223&event=somestring")
test = urllib2.urlopen(request)
Does anyone know how to get this working or has a better solution to push data from outside into an R Shiny application?
Thanks for help!
Upvotes: 2
Views: 761
Reputation: 301
My complete solution using websockets with httpuv:
library(httpuv)
startWSServer <- function(){
if(exists('server')){
stopDaemonizedServer(server)
}
app <- list(
onWSOpen = function(ws) {
ws$onMessage(function(binary, message) {
#handle your message, for example save it somewhere
#accessible by Shiny application, here it is just printed
print(message)
ws$send("message received")
})
}
)
server <<- startDaemonizedServer("0.0.0.0", 9454, app)
}
stopWSServer <- function(){
stopDaemonizedServer(server)
server <<- NULL
}
Hope this helps ;)
Upvotes: 3