diff --git a/app.R b/app.R new file mode 100644 index 0000000..6e75330 --- /dev/null +++ b/app.R @@ -0,0 +1,96 @@ +# Load necessary libraries +library(shiny) +library(jsonlite) +library(httr) +library(shinycssloaders) # For the spinner + +# Assuming you have your custom functions in a file called 'your_functions.R' +devtools::load_all() + +source("secrets") + +# Create a Bearer token header +headers.default <- add_headers( + accept = "*/*", + apikey = token4 +) + +# Load station data +allstations <- read.csv("allstations.csv") + +# Define UI for application +ui <- fluidPage( + tags$head( + tags$style(HTML(" + #main { + height: 100vh; /* Full height of the viewport */ + overflow-y: auto; /* Scroll if content overflows */ + } + .container-fluid { + height: 100vh; /* Full height of the viewport */ + display: flex; + flex-direction: column; + } + .row { + flex-grow: 1; + display: flex; + } + .col-sm-8 { + flex-grow: 1; /* Allow the main panel to grow */ + } + ")) + ), + + # Application title + titlePanel("Beaumont aka SECMONT"), + + # Sidebar for user inputs + sidebarLayout( + sidebarPanel( + width=2, + numericInput( + inputId = "daysBefore", + label = "Nb jour à check:", + value = 10, + min = 0 + ) + ), + + # Main panel for displaying plot + mainPanel( + width = 6, + withSpinner( plotOutput("dataPlot")) + ) + ) +) + +# Define server logic required to generate and plot data +server <- function(input, output) { + # Reactive expression to fetch data based on input and display spinner while loading + + + # Render the plot + output$dataPlot <- renderPlot({ + startdate <- format(Sys.Date() - input$daysBefore, "%Y-%m-%d") + test1 <- getAllFromCoord(vignass.coor, start_date = startdate, end_date = format(Sys.Date(), "%Y-%m-%d"), allstations, headers = headers.default,btw_station_sleep = .5,within_statio_sleep = 1) + + # Prepare colors + cols <- palette.colors()[1:length(unique(test1$Nom_usuel))] + names(cols) <- unique(test1$Nom_usuel) + + # Filter data + testsep <- test1 + testsep[testsep[,3] == 0 & !is.na(testsep[,3]), c(3,4)] <- NA + + plot(getDate(testsep[,2]), testsep[,3], pch = 20, col = adjustcolor(cols[testsep$Nom_usuel], .4), cex = 1.3, ylim = c(0, 8)) + + # Add legend + legend("topleft", col = cols, legend = names(cols), pch = 20, cex = 1) + + # Highlight specific date + abline(v = as.numeric(as.POSIXlt("2024-08-07", format = "%Y-%m-%d")), lwd = 3, col = "red") + }) +} + +# Run the application +shinyApp(ui = ui, server = server)