|
|
@@ -0,0 +1,173 @@ |
|
|
|
library(tidyverse) |
|
|
|
library(shiny) |
|
|
|
library(DT) |
|
|
|
library(RSQLite) |
|
|
|
library(stringr) |
|
|
|
library(plotly) |
|
|
|
|
|
|
|
dbConnect(SQLite(), "ecn.db") -> db |
|
|
|
|
|
|
|
# Index villes et spés ---- |
|
|
|
db %>% |
|
|
|
tbl("trajectoires") %>% |
|
|
|
select(Discipline, Subdivision) %>% |
|
|
|
distinct %>% |
|
|
|
collect(n = Inf) -> villespe |
|
|
|
|
|
|
|
villespe %>% |
|
|
|
select(Subdivision) %>% |
|
|
|
distinct %>% |
|
|
|
filter(Subdivision != "") %>% |
|
|
|
arrange(Subdivision) %>% |
|
|
|
pull(Subdivision) -> villes |
|
|
|
|
|
|
|
villespe %>% |
|
|
|
select(Discipline) %>% |
|
|
|
distinct %>% |
|
|
|
filter(!Discipline %>% str_detect("(car aucun vœu)|(malgré.*)|(pas de.*)")) %>% |
|
|
|
arrange(Discipline) %>% |
|
|
|
pull(Discipline) -> spes |
|
|
|
|
|
|
|
# Last update ---- |
|
|
|
Sys.setlocale("LC_TIME", "fr_FR.UTF-8") |
|
|
|
db %>% |
|
|
|
tbl("trajectoires") %>% |
|
|
|
select(timestamp) %>% |
|
|
|
distinct %>% |
|
|
|
collect(n = Inf) %>% |
|
|
|
pull(timestamp) %>% |
|
|
|
max %>% |
|
|
|
as.POSIXct %>% |
|
|
|
format(format = "%A %d %B %Y %H:%M") %>% |
|
|
|
str_to_title -> |
|
|
|
last_update |
|
|
|
|
|
|
|
# Epoch ---- |
|
|
|
db %>% |
|
|
|
tbl("trajectoires") %>% |
|
|
|
select(timestamp) %>% |
|
|
|
distinct %>% |
|
|
|
collect(n = Inf) %>% |
|
|
|
pull(timestamp) %>% |
|
|
|
min %>% |
|
|
|
as.POSIXct %>% |
|
|
|
format(format = "%A %d %B %Y %H:%M") %>% |
|
|
|
str_to_title -> |
|
|
|
epoch |
|
|
|
|
|
|
|
# Max rank ---- |
|
|
|
db %>% |
|
|
|
tbl("trajectoires") %>% |
|
|
|
select(Etudiant) %>% |
|
|
|
distinct %>% |
|
|
|
collect(n = Inf) %>% |
|
|
|
pull(Etudiant) %>% |
|
|
|
max -> |
|
|
|
max_rank |
|
|
|
|
|
|
|
db %>% dbDisconnect |
|
|
|
|
|
|
|
# UI ---- |
|
|
|
ui <- shinyUI(fluidPage( |
|
|
|
titlePanel("Celine Stalker"), |
|
|
|
p(str_c("Données à partir du ", epoch)), |
|
|
|
p(str_c("Dernières données du ", last_update)), |
|
|
|
sidebarLayout( |
|
|
|
sidebarPanel(radioButtons("Select", "Chercher par", choices = c("étudiant", "ville + spé"), selected = "étudiant"), |
|
|
|
conditionalPanel("input.Select == 'ville + spé'", |
|
|
|
selectInput("Ville", "Ville", choices = villes), |
|
|
|
selectInput("Spe", "Spé", choices = spes)), |
|
|
|
conditionalPanel("input.Select == 'étudiant'", |
|
|
|
numericInput("Etudiant", "Étudiant", 1, min = 1, max = max_rank), |
|
|
|
checkboxInput("Rang", "Afficher le rang dans un choix", value = T) |
|
|
|
)), |
|
|
|
mainPanel( |
|
|
|
conditionalPanel("input.Select == 'ville + spé'",plotlyOutput("outPlot")), |
|
|
|
conditionalPanel("input.Select == 'étudiant'", |
|
|
|
dataTableOutput("outTable")) |
|
|
|
) |
|
|
|
))) |
|
|
|
|
|
|
|
# Server ---- |
|
|
|
server <- shinyServer(function(input, output) |
|
|
|
{ |
|
|
|
outTable <- reactive({ |
|
|
|
req(input$Select, input$Ville, input$Spe, input$Etudiant) |
|
|
|
|
|
|
|
dbConnect(SQLite(), "ecn.db", on.exit(dbDisconnect(db), add = T)) -> db |
|
|
|
|
|
|
|
if (input$Select == "étudiant") |
|
|
|
{ |
|
|
|
db %>% |
|
|
|
tbl("trajectoires") %>% |
|
|
|
filter(Etudiant == input$Etudiant) %>% |
|
|
|
arrange(timestamp) %>% |
|
|
|
collect(n = Inf) %>% |
|
|
|
mutate(Date = timestamp %>% |
|
|
|
as.POSIXct %>% |
|
|
|
format(format = "%A %d %B") %>% |
|
|
|
str_to_title, |
|
|
|
Heure = timestamp %>% |
|
|
|
as.POSIXct %>% |
|
|
|
format(format = "%H:%S")) %>% |
|
|
|
select(Date, Heure, Etat, `Vœu`, Subdivision, Discipline, `Désir (non officiel) en chirurgie générale`, Rang) -> |
|
|
|
listing |
|
|
|
|
|
|
|
if (!input$Rang) |
|
|
|
{ |
|
|
|
listing %>% |
|
|
|
select(-Rang) %>% |
|
|
|
filter(is.na(lag(Subdivision)) | is.na(lead(Subdivision)) | Subdivision != lag(Subdivision) & Discipline != lag(Subdivision)) |
|
|
|
} else |
|
|
|
{ |
|
|
|
listing |
|
|
|
} |
|
|
|
} else |
|
|
|
{ |
|
|
|
db %>% |
|
|
|
tbl("trajectoires") %>% |
|
|
|
filter(Subdivision == input$Ville, |
|
|
|
Discipline == input$Spe) %>% |
|
|
|
select(Etudiant) %>% |
|
|
|
arrange(Etudiant) %>% |
|
|
|
collect(n = Inf) %>% |
|
|
|
distinct(Etudiant, .keep_all = T) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
output$outPlot <- renderPlotly({ |
|
|
|
dbConnect(SQLite(), "ecn.db", on.exit(dbDisconnect(db), add = T)) -> db |
|
|
|
|
|
|
|
db %>% |
|
|
|
tbl("trajectoires") %>% |
|
|
|
filter(Subdivision == input$Ville, |
|
|
|
Discipline == input$Spe) %>% |
|
|
|
select(Etudiant) %>% |
|
|
|
distinct(Etudiant) %>% |
|
|
|
collect(n = Inf) %>% |
|
|
|
pull(Etudiant) -> listing |
|
|
|
|
|
|
|
db %>% |
|
|
|
tbl("trajectoires") %>% |
|
|
|
filter(Etudiant %in% listing) %>% |
|
|
|
collect(n = Inf) %>% |
|
|
|
mutate(Date = timestamp %>% |
|
|
|
as.POSIXct, |
|
|
|
Etudiant = Etudiant %>% factor, |
|
|
|
Rang = if(Rang %>% is.character) Rang %>% str_replace("(\\d+)(/\\d+)?", "\\1") %>% as.numeric else Rang) -> listing |
|
|
|
|
|
|
|
listing %>% |
|
|
|
mutate(Rang = ifelse(Subdivision != input$Ville | Discipline != input$Spe, NA, Rang)) -> listing |
|
|
|
|
|
|
|
if (input$Select == "étudiant") |
|
|
|
ggplot() |
|
|
|
else |
|
|
|
listing %>% |
|
|
|
ggplot(aes(x = Date, y = Rang, color = Etudiant)) + |
|
|
|
geom_line() + |
|
|
|
geom_point() |
|
|
|
}) |
|
|
|
output$outTable <- renderDataTable(outTable(), options = list(paging = F, searching = F, info = F)) |
|
|
|
}) |
|
|
|
|
|
|
|
shinyApp(ui, server) |