Skip to content
Snippets Groups Projects
trends.R 2.37 KiB
Newer Older
Vincent DUPONT's avatar
Vincent DUPONT committed
### Ranking tab

##################
### Data objects
##################



TRENDS_tab <- reactive({
  
  date1 <- min(JSON_cons_har$consultation_date)
  date2 <- max(JSON_cons_har$consultation_date)
  
  if(input$TRENDStype == "residence_area"){
    consultation_har_filter(JSON_cons_har,
                            new_attack = input$TRENDSnew_attack,
                            diagn = input$TRENDSdiagn,
                            sex = input$TRENDSsex,
                            minAge = input$TRENDSage[1], maxAge = input$TRENDSage[2]
    ) %>%
      select(id_residence_place, consultation_date) %>%
      group_by(id_residence_place)
  } else if(input$TRENDStype == "center"){
    consultation_har_filter(JSON_cons_har,
                            new_attack = input$TRENDSnew_attack,
                            diagn = input$TRENDSdiagn,
                            sex = input$TRENDSsex,
                            minAge = input$TRENDSage[1], maxAge = input$TRENDSage[2]
    ) %>%
      filter(consultation_date >= date1 & consultation_date <= date2) %>%
      select(id_center, consultation_date) %>%
      group_by(id_center) %>%
      dplyr::summarise(count = n(), trend = decompose(x = consultation_date, date1 = date1, date2 = date2)) %>%
      inner_join(healthcenter_list, by = c("id_center" = "id_center"))
  } else if(input$TRENDStype == "infection_place"){
    consultation_har_filter(JSON_cons_har,
                            new_attack = input$TRENDSnew_attack,
                            diagn = input$TRENDSdiagn,
                            sex = input$TRENDSsex,
                            minAge = input$TRENDSage[1], maxAge = input$TRENDSage[2]
    ) %>%
      filter(consultation_date >= date1 & consultation_date <= date2) %>%
      select(id_infection_place, consultation_date) %>%
      group_by(id_infection_place) %>%
      dplyr::summarise(count = n(), trend = decompose(x = consultation_date, date1 = date1, date2 = date2)) %>%
      inner_join(residencial_area_list, by = c("id_infection_place" = "id"))
  }
  
  
})

##################
### Table
##################

output$TRENDS_table <- renderDataTable({
  TRENDS_tab() %>%
    select(name, count, source, trend) %>%
    plyr::arrange(-count) %>% 
    mutate(source = ifelse(source == "BR", tr("BR"), tr("FG"))) %>%
    plyr::rename(c("name" = tr("name"), "count" = tr("cases"), "source" = tr("country")))
}, rownames= FALSE)