如何在shinyapp内创建交互式环境

时间:2016-06-22 15:30:17

标签: shiny httr

我在sever.R中使用以下查询,它在本地运行时工作正常。但是,当应用程序部署在shinyapps.io或Web托管服务器上时,我收到以下错误

错误:需要交互式环境

在shinyapp上部署代码:

updateStatus <- function(text, token, link=NULL) {
## text prepocessing
text <- enc2utf8(text)
text <- gsub(" ", "+",text)

## query including text
query <- paste('https://graph.facebook.com/me/feed?message=', text, sep="")
## adding URL
if (!is.null(link)){
query <- paste(query, "&link=", link, sep="")
}
## making query
if (class(token)[1]=="config"){
url.data <- POST(query, config=token)
}
if (class(token)[1]=="Token2.0"){
url.data <- POST(query, config(token=token))
}

if (class(token)[1]=="character"){
url <- paste0(query, "&access_token=", token)
url.data <- POST(url)
}
if (class(token)[1]!="character" & class(token)[1]!="config" & class(token)[1]!="Token2.0") {
stop("Error in access token. See help for details.")
}
## output
if (url.data$status_code==200){
id <- fromJSON(rawToChar(url.data$content))$id
if (is.null(id)){
message("Failed update. OAuth token does not have permission to update status. ",
"See ?fbOAuth for more details.")
}
message("Success! Link to status update: ", paste("http://www.facebook.com/", id, sep=""))
}
if (url.data$status_code==400){
error <- fromJSON(rawToChar(url.data$content))$error$code
message <- fromJSON(rawToChar(url.data$content))$error$message
if (error==2500){
message("Failed update. OAuth token does not have permission to update status. ",
"See ?fbOAuth for more details.")
}
if (error!=2500){
message("Failed update.", message)
}
}
}

observeEvent(input$FBButton,{
Sys.setenv("HTTR_SERVER_PORT" = "1410/")
updateStatus(paste("Analysis by using www.abc.com",sep=""), 
token=oauth2.0_token(oauth_endpoints('facebook'), 
oauth_app('facebook', 'app', 'key'),
scope = 'ads_management',
type = 'application/x-www-form-urlencoded', 
cache = FALSE)$credentials$access_token, 
link = "www.rstudio.com")
})

0 个答案:

没有答案