Commit 74050659 authored by Aqeel Padaria's avatar Aqeel Padaria

add google authenticator, remove plot download

parent e485a3db
......@@ -3,7 +3,7 @@ Title: Time Series Aggregator GUI
Version: 0.0.0.9000
Authors@R: person("Aqeel", "Padaria", email = "aqeel.padaria@gramener.com", role = c("aut", "cre"))
Description: GUI Frontend for the Time Series Aggregated Forecasting tool.
Depends: R (>= 3.3.2), openxlsx, shiny, DT, shinycssloaders, ggplot2
Depends: R (>= 3.3.2), openxlsx, shiny, DT, shinycssloaders, ggplot2, googleAuthR
License:
Encoding: UTF-8
LazyData: true
......
......@@ -8,13 +8,17 @@
forecastUI <- function(directory = ".", run = TRUE)
{
origwd <- getwd()
setwd(directory)
library(openxlsx)
library(ggplot2)
library(shiny)
library(DT)
library(shinycssloaders)
library(googleAuthR)
origwd <- getwd()
setwd(directory)
css <- "
.shiny-output-error { visibility: hidden; }
......@@ -28,7 +32,49 @@ server = shinyServer(
function(input, output, session) {
source("google_auth.R",local = T)
observe({
user<<-user_details()
if(is.null(user)){
output$logintext<- renderUI({
"Please Login !"
})
}else{
if(user$auth=="bad"){
output$logintext<- renderUI({
"Authentication Problem! Please logout and login
with correct email id or contact admin."
})
shinyjs::hide("demo-switch")
shinyjs::disable("uploadbox")
}else{
if(user$fullname=="") user$fullname=user$displayName
profilename<<-user$fullname
profileimage<<-user$imageurl
#######Server : Profile ############
output$profilepic<-renderText({
profileimage=str_split_fixed(profileimage,"\\?sz",2)[1]
c('<img src="',profileimage,'" height="75" width="75"
class="img-circle">')
})
output$profilename <- renderText({
profilename
})
output$logintext<- renderUI({
"Logged in as"
})
output$datasetsAvailable <- renderUI({
files <- dir()
......@@ -490,16 +536,16 @@ server = shinyServer(
openxlsx::addWorksheet(wb, "Forecast")
openxlsx::writeData(wb, sheet = "Forecast", x = newvals, colNames = TRUE, rowNames = FALSE)
png("graph.png")
p <- getPlot()
print(p)
dev.off()
openxlsx::addWorksheet(wb, "Plot", gridLines = FALSE)
openxlsx::insertImage(wb, "Plot", "graph.png", width=8, height = 4, units = "in")
# png("graph.png")
# p <- getPlot()
# print(p)
# dev.off()
# openxlsx::addWorksheet(wb, "Plot", gridLines = FALSE)
# openxlsx::insertImage(wb, "Plot", "graph.png", width=8, height = 4, units = "in")
#openxlsx::insertPlot(wb, "Plot", width=8, height = 4, fileType = "png", units = "in")
openxlsx::saveWorkbook(wb,file, overwrite = T)
unlink("graph.png")
# unlink("graph.png")
})
......@@ -554,6 +600,9 @@ server = shinyServer(
HTML(txtVal)
})
} #Un-authenticated
} #Not-logged in
}) #observe
}
)
......@@ -569,7 +618,8 @@ ui = #ui.R
sidebarPanel(
googleAuthUI("googleauth"),
textOutput("profilename"),
uiOutput("datasetsAvailable"),
uiOutput("dataOptions"),
......
email_access<<-
c("@gramener.com")
get_auth_info=function (id = "me")
{
url <- sprintf("https://www.googleapis.com/plus/v1/people/%s",
id)
g <- googleAuthR::gar_api_generator(url, "GET")
req <- g()
user<- req$content
email=user$emails$value
auth="bad"
for(i in 1:length(email_access)){
if(grepl(email_access[i],email)) auth="good"
}
profile=list(displayName=user$displayName,fullname=paste(user$name$givenName,user$name$familyName,sep=" "),
email=email,imageurl=user$image$url,auth=auth)
profile
}
options(googleAuthR.scopes.selected = c("https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"))
options("googleAuthR.webapp.client_id" = "1063850569928-ktni7ff0ef0avt21611240hj6oi8jrkq.apps.googleusercontent.com")
options("googleAuthR.webapp.client_secret" = "5NJfGlsEArtEC0_MhZzeH9pe")
access_token <- callModule(googleAuth, "googleauth",login_class = "btn btn-primary",
logout_class = "btn btn-primary", login_text = "Log In",
logout_text = "Log Out",access_type="offline")
output$token<-renderText({
googleAuthR::gar_token_info()
})
#
## to use in a shiny app:
user_details <- reactive({
at=access_token()
if(!is.null(shiny::isolate(at))){
#print("not null")
if(!is.null(at$credentials$access_token)){
#print("good token")
at_back<<-at
}else{
#print("bad token")
at=at_back
}
with_shiny(get_auth_info, shiny_access_token = at)
}else{
return(NULL)
}
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment