I am using the below query in sever.R and it works fine when run locally. However, when the app is deployed over shinyapps.io or on a web hosting server, I get the following error
Error: Requires an interactive environment
Code deployed over 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")
})
Related
I've tried the method of showing lists in a shiny app in the following link:
How to print lists of lists of uneven length in Shiny and nothing is displayed so far.
ui <- fluidPage(
verbatimTextOutput("res")
)
server <- function(input, output, session) {
output$res<-renderPrint({
x=list(nam=('d','h','k','m'),num=(3,2,8,9))
a=tapply(x[,1],x[,2],summary)
})}
shinyApp(ui = ui, server = server)
I have a number of individuals who log into a shiny-server application where they all interact. After the app stops, I load another application, they each click ``reload'', and they all interact on the new application.
If someone clicks ``reload'' early, then everyone needs to re sign in. Is there any way to avoid this. I'd like to just regenerate shiny's default reload-page.
I'm not sure how your reaload works as you havent posted any code, however you can force F5 page refresh like so. parts of the code example are taken from here`
library(shiny)
library(shinyjs)
jscode <- "shinyjs.reload = function() { window.location.reload(true); }"
ui <- fluidPage(
useShinyjs(),
extendShinyjs(text = jscode),
textInput("text", "Text"),
actionButton("reload", "Refresh app")
)
server <- function(input, output, session) {
observeEvent(input$reload, {
js$reload();
})
}
shinyApp(ui = ui, server = server)
It is my understanding that the open source version of Shiny Server does not support authentication.
We have an environment that uses the WebSEAL proxy service for authenticating user and channelling their access through to web applications.
We wish to expose a Shinyapp to authenticated users with the content served up being dependent on user group membership. WebSEAL is able to set the iv_user and iv_group variables in the HTTP Headers to pass onto the shinyapp via the junction, but the Open Source Shiny Server seems to be unable to access them (I.E. via the session$clientData object).
I’m wondering if anyone has worked out a way for an Open Source Shiny Server app to access the HTTP Headers to determine the user and groups.
If you just want to access HTTP headers, the UI can be a function that accepts a single argument for a request object that implements the Rook specification.
library(shiny)
ui <- function(request) {
print(as.list(request))
# get HTTP headers like request$HTTP_HEADER_NAME (all caps)
fluidPage(
tags$pre(
paste(capture.output(as.list(request)), collapse = "\n")
)
)
}
server <- function(input, output) {
}
shinyApp(ui, server)
One way to serve different pages depending on an HTTP header could be like this -
unauthorizedPage <- function() {
"Unauthorized"
}
memberPage <- function() {
fluidPage(
"Member page"
)
}
ui <- function(request) {
# serve memberPage() if request contains header `iv_group: member`
# otherwise serve unauthorizedPage()
if (!identical(request$HTTP_IV_GROUP, "member"))
return(unauthorizedPage())
memberPage()
}
server <- function(input, output) {
}
shinyApp(ui, server)
When clicking on action button, I can see the google sheet downloading and date printed in console but the filetime in renderPrint is not updating?
library(httr)
set_config( config( ssl_verifypeer = 0L ) )
library(googlesheets)
suppressMessages(library(dplyr))
library(shiny)
library(shinydashboard)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
fluidRow(
#One action button to download data from google spreadsheet
actionButton("refreshbutton", label = "Refresh"),
#two textoutput to show date of downloaded file
textOutput("refreshdate")
)
)
)
)
server <- function(input, output) {
observeEvent(input$refreshbutton, {
#On click download data from google spreadsheet
pulldata <- gs_key("19bPhlp7MjDZFNJcDUmHGJDxkh2h2U5j05S0c18HfBgE") %>%
gs_read_csv(ws="vs working", col_names=TRUE)
#Write data in csv
write.csv(pulldata, file = "attrition.csv")
data <- read.csv(file="attrition.csv", header = TRUE)
#capture modified time from csv
filetime <- file.mtime("attrition.csv")
print(filetime)
#inform on completion after refresh
})
#print filetime in refreshdate1
output$refreshdate <- renderPrint({
filetime # <- This is not updating???
})
}
shinyApp(ui, server)
Along with the above code, when Google spreadsheet is downloading, I assume the site should go to grey mode indicating refresh - this also is not happening? I mean it should show somehow that new data is in process till complete?
The reason why it is not working is because the scope of the filetime variable is within the observeEvent. You cannot assign a variable outside its scope using observeEvent, instead use eventReactive.
Just checked it, gs_key is throwing an error for me even in R console, otherwise this is the solution you were looking for regarding reactivity.
server <- function(input, output) {
observeEvent(input$refreshbutton, {
#On click download data from google spreadsheet
pulldata <- gs_key("19bPhlp7MjDZFNJcDUmHGJDxkh2h2U5j05S0c18HfBgE") %>%
gs_read_csv(ws="vs working", col_names=TRUE)
#Write data in csv
write.csv(pulldata, file = "attrition.csv")
#read.csv(file="attrition.csv", header = TRUE)
})
filetime <- eventReactive(input$refreshbutton, {
file.mtime("attrition.csv")
})
#print filetime in refreshdate1
output$refreshdate <- renderPrint({
filetime()
})
}
Error message:
Expected content-type:
application/atom+xml; charset=UTF-8
Actual content-type:
text/html; charset=UTF-8
I am using phantomjs to print the webpage and create a pdf. As the UI needs the user's authentication before finding the data, I used persistent cookies to authenticate the user. But somehow I got login screen every time in the created PDF. I observed that the user authenticated successfully and also the result's webpage showing proper result (debug logs showing the proper data array) but while printing the web page or creating a PDF, it somehow gets the login screen. Sometimes I observed that I got two different cookies in my PHP code while getting the report data and in javascript 'document.cookies'.
Please let me know how can I fix this.
var page = require('webpage').create(),
system = require('system'), t, address;
page.settings.userName = 'myusername';
page.settings.password = 'mypassword';
if (system.args.length === 1) {
console.log('Usage: scrape.js ');
phantom.exit();
} else {
t = Date.now();
address = system.args[1];
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
} else {
t = Date.now() - t;
var title = page.evaluate(function() { return document.title;})
console.log('Page title is ' + title);
console.log('Loading time ' + t + ' msec');
}
phantom.exit();
});
}
Another piece of code of sending a cookie file
bin/phantomjs --cookies-file=/tmp/cookies.txt --disk-cache=yes --ignore-ssl-errors=yes /phantomjs/pdf.js 'username' 'params' '/tmp/phantomjs_file' /tmp/phantom_pdf.pdf
And
phantomjs --cookies-file=cookies.txt examples/rasterize.js localhost:7000/reports /tmp/report.pdf