Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenpp7 committed Apr 7, 2021
1 parent 7e18946 commit b38cd52
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 7 deletions.
6 changes: 4 additions & 2 deletions R/divewatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand All @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions R/prep_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand All @@ -29,16 +30,15 @@


prep_data <- function (data = NA,
#email = NA,
email = NA,
path = getwd()){

### READ DATA
#-------------

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 = ""))
Expand Down
100 changes: 100 additions & 0 deletions divewatchrshiny/app.R
Original file line number Diff line number Diff line change
@@ -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('<div class="fa-3x"><i class=\'fa fa-spinner fa-spin\' id=\'loadingIcon\'></i></div>')))
),
# 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)
4 changes: 3 additions & 1 deletion man/divewatch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/prep_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b38cd52

Please sign in to comment.