diff --git a/R/divewatch.R b/R/divewatch.R index 3076bee..2828d55 100644 --- a/R/divewatch.R +++ b/R/divewatch.R @@ -7,6 +7,7 @@ #' #' @param data The URL ID of the database in google sheets, if no URL is provided a mock dataset generated #' by the test_data function will be read +#' @param email email account that will be used to access the Logbook in Google Spreadsheet #' #' @author Ruben Perez Perez #' @@ -22,8 +23,9 @@ #' } -divewatch <- function(data = NA){ - prep_data(data) +divewatch <- function(data = NA, + email = NA){ + prep_data(data, email) download.file("https://raw.githubusercontent.com/rubenpp7/divewatchr/master/files/overview.Rmd", "overview.Rmd") render("overview.Rmd") diff --git a/R/prep_data.R b/R/prep_data.R index 11497a6..2f8feb0 100644 --- a/R/prep_data.R +++ b/R/prep_data.R @@ -8,6 +8,7 @@ #' @param data The URL ID of the database in google sheets, if no URL is provided a mock dataset generated #' by the test_data function will be read #' @param path directory location where the files will be read from or written into +#' @param email email account that will be used to access the Logbook in Google Spreadsheet #' #' @author Ruben Perez Perez #' @@ -29,7 +30,7 @@ prep_data <- function (data = NA, - #email = NA, + email = NA, path = getwd()){ ### READ DATA @@ -37,8 +38,7 @@ prep_data <- function (data = NA, if(!is.na(data)){ # From Google sheets -#gs4_auth(email) -gs4_deauth() +gs4_auth(email) (scuba_log <- read_sheet(data, sheet = "logbook", na = "")) (scuba_geo <- read_sheet(data, sheet = "coordinates", na = "")) (scuba_typ <- read_sheet(data, sheet = "divetypes", na = "")) diff --git a/divewatchrshiny/app.R b/divewatchrshiny/app.R new file mode 100644 index 0000000..8a2ac45 --- /dev/null +++ b/divewatchrshiny/app.R @@ -0,0 +1,100 @@ +# +# This is a Shiny web application. You can run the application by clicking +# the 'Run App' button above. +# +# Find out more about building applications with Shiny here: +# +# http://shiny.rstudio.com/ +# + + + +library(shiny) +library(divewatchr) + + +path <<- "." +homed <<- getwd() + + +# Define UI for application that draws a histogram +ui <- fluidPage( + + + conditionalPanel(condition="$('body').hasClass('disconnected')", tags$div("Disconnected\n refresh browser.",id="disconnectmess")), + tags$script('Shiny.addCustomMessageHandler("setcookie",function(cookie) {document.cookie=cookie;});'), + + fluidRow( + column(9,titlePanel("Divewatchr")), + column(3,conditionalPanel(condition="$('html').hasClass('shiny-busy')", HTML('
'))) + ), + # Application title + #titlePanel("Old Faithful Geyser Data"), + + + + + # Sidebar with a slider input for number of bins + sidebarLayout( + sidebarPanel( + textInput('url','Google Spreadsheet page ID', value = "1PpXTVS8LdzbvwLHyAAhR2MdT9Iwdy-hiqJknUzF7Yqo"), + textInput('email','Email account to access the Logbook', value = ""), + actionButton("load","Load",icon("refresh")), + uiOutput("downloadbutton") # to download the html file from divewatch() + + ), + + # Show a plot of the generated distribution + mainPanel( + htmlOutput("htmldives") + )), + + + + + + + + +) + +# Define server logic required to draw a histogram +server <- function(input, output, session) { + + values<-reactiveValues(sourceURL="") + + observe({ + query <- parseQueryString(session$clientData$url_search) + if (!is.null(query[["baseurl"]]) & !is.null(query[["resource"]])) { + baseurl <- query[["baseurl"]] + resource <- query[["resource"]] + values$sourceURL <- paste0(baseurl, '/resource?r=', resource) + }} ) + + observeEvent(input$load,{ + if(!is.null(input$file)) + values$sourceURL<-input$file[4] + else if(!is.null(input$url)) + values$sourceURL<-input$url + + }) + + CheckDataset<-reactive({ + req(values$sourceURL) + return(divewatch (values$sourceURL, input$email)) + }) + + + + output$htmldives <- renderUI ({ + IPTreport<-CheckDataset() + + includeHTML("overview.html") + + }) + + +} + +# Run the application +shinyApp(ui = ui, server = server) diff --git a/man/divewatch.Rd b/man/divewatch.Rd index bb06a43..2304256 100644 --- a/man/divewatch.Rd +++ b/man/divewatch.Rd @@ -4,11 +4,13 @@ \alias{divewatch} \title{Creates an overview of the logbook} \usage{ -divewatch(data = NA) +divewatch(data = NA, email = NA) } \arguments{ \item{data}{The URL ID of the database in google sheets, if no URL is provided a mock dataset generated by the test_data function will be read} + +\item{email}{email account that will be used to access the Logbook in Google Spreadsheet} } \value{ Creates an overview.html file with an overview of the diving logbook and creates a Fig folder with the images from the overview diff --git a/man/prep_data.Rd b/man/prep_data.Rd index 522c72b..21b213f 100644 --- a/man/prep_data.Rd +++ b/man/prep_data.Rd @@ -4,12 +4,14 @@ \alias{prep_data} \title{Prepares the data} \usage{ -prep_data(data = NA, path = getwd()) +prep_data(data = NA, email = NA, path = getwd()) } \arguments{ \item{data}{The URL ID of the database in google sheets, if no URL is provided a mock dataset generated by the test_data function will be read} +\item{email}{email account that will be used to access the Logbook in Google Spreadsheet} + \item{path}{directory location where the files will be read from or written into} } \value{