Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(base64enc)
- library(bslib)
- library(DBI)
- library(plotly)
- library(shiny)
- library(shinythemes)
- library(stringr)
- AddAllOption <- function(DF)
- {
- # Position to insert the new row (after the second row)
- InsertPos <- 1
- DataFramePart1 <- DF[1:InsertPos - 1,,drop = FALSE]
- DataFramePart2 <- DF[(InsertPos):nrow(DF),,drop = FALSE]
- NewRow <- c('All')
- # Combining the dataframe parts with the new row
- NewDataframe <- rbind(DataFramePart1, NewRow, DataFramePart2)
- return(NewDataframe)
- }
- # On Desktop at home:
- # source("F:/Data/Dropbox/#1 - CC/R/RRUtils.R")
- # On Laptop:
- source("C:/Users/Richard/Dropbox/#1 - CC/R/RRUtils.R")
- # "F:\Data\Dropbox\#1 - CyclingCanada\R\RRUtils.R"
- WorkingDirectory <- "C:/Users/Richard/Dropbox/#1 - CC/R/CCDashboard"
- # on Desktop at home:
- if (GetPCName() != "RRLAPTOP")
- WorkingDirectory <- "F:/Data/Dropbox/#1 - CC/R/CCDashboard"
- setwd(WorkingDirectory)
- Config <- config::get()
- DBDriver <- Config$Driver
- DBName <- Config$DBName
- DBHost <- Config$DBHost
- DBPort <- Config$DBPort
- DBUser <- Config$DBUser
- DBPassword <- rawToChar(base64decode(Config$DBPassword))
- Conn <- dbConnect(odbc::odbc(),
- Driver = DBDriver, Server = DBHost, Port = DBPort,
- Database = DBName, UID = DBUser, PWD = DBPassword)
- RiderYearsSQL <- Config$SQLRiderYears
- RiderYears <- dbGetQuery(Conn, RiderYearsSQL)
- RiderYears <- AddAllOption(RiderYears)
- # ChoicesList <- c("Andrew", "Bob", "Chris")
- # ChoicesList <- as.character(seq(1, 10, by = 1))
- # ChoicesList <- RiderYears$cyclingyear
- # ChoicesList <- as.character(RiderYears$cyclingyear)
- # TestList <- list(as.character(seq(2024, 2000, by = -1)))
- # names(TestList) <- as.character(TestList)
- # names(TestList) <- as.character(TestList)
- # TestList <- RiderYears$cyclingyear
- # append(TestList, "All", after = 1)
- # names(TestList) <- as.character(TestList)
- Frequencies <- c("Year", "Departure Hour", "Day of Week", "Indoor/Outdoor")
- BestOf <- c(
- "Highest Average Cadence"
- , "Highest Average HR"
- , "Highest Average Power"
- , "Highest Average Speed"
- , "Distance (KM)"
- , "Duration (Time)"
- )
- Quarters <-
- data.frame("Quarters" = c("Q1 (Jan - Mar)", "Q2 (Apr - Jun)", "Q3 (Jul - Sep)", "Q4 (Oct - Dec)"))
- Quarters <- AddAllOption(Quarters)
- Months <-
- data.frame("Months" = month.name)
- Months <- AddAllOption(Months)
- SQLRiderTotals <- Config$SQLRiderTotalsByYear
- RiderTotals <- dbGetQuery(Conn, SQLRiderTotals)
- # TotalSeconds for 2014 is too high to be correct, not sure why
- # RiderTotals[]
- RiderTotals[RiderTotals$rideryear == 2014,]$totalseconds <-
- RiderTotals[RiderTotals$rideryear == 2014,]$ridecount *
- RiderTotals[RiderTotals$rideryear == 2015,]$totalseconds /
- RiderTotals[RiderTotals$rideryear == 2015,]$ridecount
- MaxDist <- floor(max(RiderTotals$totalkilometers) / 1000) * 1000
- # source("OldShinyUIFunction.R")
- source("UpdatedShinyUIFunction.R")
- server <- function(input, output) {
- # UIFreq <- reactive(input$UIFreq)
- # UIYear <- reactive(input$UIYear)
- # UIQuarter <- reactive(input$UIQuarter)
- # UIMonth <- reactive(input$UIMonth)
- # req(UIFreq, UIYear, UIQuarter, UIMonth)
- # renderPlotly(
- # Freq <- UIFreq() # ("Year", "Departure Hour", "Day of Week", "Indoor/Outdoor")
- # FreqIndex <- match(Freq, Frequencies)
- # XAxisLabel <- Frequencies[FreqIndex]
- XAxisLabel <- "RRTest"
- Plot1 <-
- renderPlot({
- ggplot(RiderTotals, aes(x = rideryear, y = totalkilometers)) +
- scale_x_continuous (
- name = XAxisLabel
- , labels = as.character(RiderTotals$rideryear)
- , breaks = RiderTotals$rideryear
- ) +
- scale_y_continuous (
- "Kilometers",
- breaks = seq(0, MaxDist, by = 250)
- ) +
- geom_col(fill = 'Green')
- })
- # sink("C:/Users/Richard/Dropbox/#1 - CC/R/May28_2024.txt")
- # print(summary(Plot1))
- # sink()
- output$Plot1 <- Plot1
- }
- # rsconnect::deployApp(account = 'richardrogers', appDir = "C:/Users/Richard/Dropbox/#1 - CC/R/CCDashboard", appFiles = c("ShinyGUI.R", "config.yml"))
- shinyApp(ui = ui, server = server)
Add Comment
Please, Sign In to add comment