about_ui <- function(id) {
  ns <- NS(id)
  navbarMenu(
    "About",
    # About the tool -------------------------------------------------------
    tabPanel(
      "About this tool",
      tags$br(),

      p("data4health is a tool developed as part of the HARMONIZE project to facilitate the access, preprocessing, and aggregation of health data at customized spatiotemporal resolutions.
        Originally designed for data from Colombia, Brazil, Peru, and the Dominican Republic, the tool is intended to be adaptable for any linelist health data."),
      tags$div(
        style = "text-align: center;",
        tags$img(src = "flowchart.svg", style = "max-width: 80%; height: auto;")
      ),
      h4("Modes of Operation"),
      p("The R package offers two modes of operation depending on the user's coding experience:"),
      tags$ul(
        tags$li("For users with coding experience: A wide range of functions can be directly used within R."),
        tags$li("For non-coding users: A graphical user interface (GUI) guides users through the data processing pipeline in an intuitive, user-friendly way.")
      ),

      h4("Key Features of the R Package"),
      tags$ul(
        tags$li("Instructions on how to access health data"),
        tags$li("Functions for cleaning and preprocessing health data"),
        tags$li("Spatial harmonisation, allowing aggregation to any coarser administrative unit"),
        tags$li("Temporal harmonisation, enabling aggregation to epidemiological weeks or months"),
        tags$li("Data visualization capabilities"),
        tags$li("Output as a .csv file, formatted to meet user-specified requirements")
      ),
      # p("This tool was developed within the HARMONIZE project. It aims to streamline health data analysis for researchers and decision makers wihthout the need of coding. It contains the following steps:"),
      # fluidRow(
      #   style = "padding-left: 4%;",
      #   div(tags$b("1. Access data:"),"	In the case of publicly available data,..... And in the case of restricted data, the information on who to contact will be given."),
      #   div(tags$b("2. Preprocess:"),"	Cleaning the data of inconsistencies and doing quality analysis"),
      #   div(tags$b("3. Load:"),"  In case you already have the data prepared, load it directly in."),
      #   div(tags$b("4. Aggregate:"),"			Aggregate it."),
      #   div(tags$b("5. Visualise:")," 			Visualise a a timeseries or as a table")
      # ),
      
      tags$br(),
      p("You can input data at any step and also download the result of any step."),
      p("The 'access data' is currently available for Brazil and will be available for Peru, Colombia and Dominican Republic in the near future. All other steps can be performed for any data as long as it has the correct data format.")
    ),
    # About the project ------------------------------------------------------
    tabPanel(
      "About the project",
      tags$br(),
      tags$div(
        style = "border: 2px solid #E296B5; border-radius: 10px; padding: 10px; background-color: #E296B5;",
        p("HARMONIZE will develop cost-effective and reproducible digital tools for stakeholders in hotspots affected by a changing climate in Latin America & the Caribbean (LAC), including cities, small islands, highlands, and the Amazon rainforest.", style = "color: white; font-weight: bold; font-size: 16px;")
      ),
      tags$br(),
      p("Extreme climatic events, environmental degradation and socio-economic inequalities exacerbate the risk of infectious disease epidemics. However, there are significant challenges in obtaining science-based evidence to understand and predict the impacts of extreme events and landscape changes on disease risk, leaving communities in climate change hotspots, vulnerable to increasing health threats. This is partly due to a lack of longitudinal and localised data, describing fine-scale environmental changes in remote and under-resourced areas, a lack of investment and capacity building in data science and software tools, and a lack of trained research software engineers and data scientists. The HARMONIZE project convenes a transdisciplinary community of practitioners, community-based organisations, local governments, software  engineers and data scientists to address these challenges. "),
      p("The main goal of the project is to develop cost-effective and reproducible digital tools for decision-makers in climate change hotspots in Latin America & the Caribbean, including cities, small islands, highlands, and the Amazon rainforest. HARMONIZE will collate existing multi-source climate, environmental, socio-economic and health data, and collect new longitudinal ground-truth data using drone technology and low-cost weather sensors, to calibrate and downscale coarser-resolution Earth Observation, climate reanalysis and forecast datasets in areas most relevant for disease transmission. The HARMONIZE digital toolkits will allow local researchers and users, including national disease control programs, to link, interrogate and use multi-scale spatiotemporal data, to understand the links between environmental change and infectious disease risk in their local context, and to build robust early warning and response systems in low-resource settings."),
      tags$div(
        style = "text-align: center;",
        tags$img(src="harmonize_banner.png", style = "max-width: 80%; height: auto;")
      ),
      tags$br(),
      p("At the core of HARMONIZE is the digital infrastructure, which collects and post-processes different data streams to create harmonised datasets across different spatiotemporal scales and communities of practice. Existing datasets, including global Earth observations from satellite images and gridded climate reanalysis, and forecast data, will be combined with new data collected from drones and weather sensors during the project, to improve classification, bias-correction and downscaling of existing products. This will be merged with socio-economic, demographic and health system data (i.e., census, micro survey, and health service data) and disease surveillance data (e.g., case reports for dengue, chikungunya, Zika, malaria, leptospirosis, Chagas, etc.) collected via online platforms and provided by public health practitioners. From this core digital infrastructure, digital toolkits will be designed for key decision-makers operating across a range of hotspot, including cities, the Amazon rainforest, highland areas, and small islands. This new knowledge and technology will have lasting benefits for the wider community of practice and generate new evidence to design strategies to protect local communities from the adverse health impacts of a changing climate."),
      p(HTML(paste0("For more information about the project please visit the ", tags$a(" HARMONIZE webpage", href="https://www.harmonize-tools.org/", target="_blank"))))
    )
    # Documentation #############
    # tabPanel(
      # "Documentation",
      # conditionalPanel(
      #   condition = "output.document_page == 'start'",
      #   h4("Documentation"),
      #   h5("Examples for cleaning"),
      #   p("Here you can find examples on how to interpret and clean health data for different countries and diseases."),
      #   tags$b("Brazil:"),
      #   tags$ul(
      #     tags$li(actionLink("go_dengue","Dengue")),
      #     tags$li(actionLink("go_malaria","Malaria")),
      #     tags$li("Leptospirosis")

      #   ),
      #   tags$br(),
      #   h5("Dictionary"),
      #   p("The dictionaries are the key to understanding the health data sets. They contain an explanation on what variable each column contains and, for categorical variables, also explains what each category means."),
      #   tags$b("Brazil"),
      #   tags$ul(
      #     tags$li(actionLink("download_br_dengue_dictionary","Dengue")),
      #     tags$li(actionLink("download_br_dengue_dictionary", "Malaria"))
      #   ),
      #   tags$b("Colombia"),
      #   tags$ul(
      #     tags$li("Dengue"),
      #     tags$li("Malaria")
      #   ),
      #   tags$b("Dominican Republic"),
      #   tags$ul(
      #     tags$li("Dengue"),
      #     tags$li("Malaria")
      #   ),
      #   tags$b("Peru"),
      #   tags$ul(
      #     tags$li("Dengue"),
      #     tags$li("Malaria")
      #   )
      # ),
      # conditionalPanel(
      #   condition = "output.document_page == 'br_dengue'",
      #   actionLink("go_brdengue_start","Go back to overview"),
      #   "Coming soon!"
      # ),
      # conditionalPanel(
      #   condition = "output.document_page == 'br_malaria'",
      #   tags$br(),
      #   actionLink("go_brmalaria_start", "Go back to overview"),
      #   tags$br(),

      #   p("This document aims at introducing dengue data to someone with no previous experience. Before starting it is necessary to have the health data, instructions on how to obtain these are in the ReadMe of this project."),
      #   p("The steps include:"),
      #   tags$ol(
      #     tags$li("Downloading the data"),
      #     tags$li("Getting to know the data: variables and completeness"),
      #     tags$li("Information on the patients: Age, Sex, Pregnancy and Race"),
      #     tags$li("Classifying the malaria cases: detection and symptoms"),
      #     tags$li("Timeline of malaria cases: distribution throughout the year, and course of the cases"),
      #     tags$li("Mapping spatially: municipality types, malaria types and incidences")
      #   ),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_1", mode = "r", theme="tomorrow", readOnly=TRUE, height="160",
      #   #             value= "# load packages
      #   # packages  <- c('microdatasus', 'dplyr', 'purrr', 'ggplot2','tidyr',
      #   #                'lubridate','geobr', 'stringr')
      #   # invisible(install.packages(setdiff(packages, rownames(installed.packages()))))
      #   # invisible(lapply(packages, function(pkg) suppressMessages(require(pkg, character.only = TRUE))))

      #   # # other options
      #   # options(scipen = 999)
      #   # options(timeout = 900)

      #   # # load functions
      #   # files.sources <-  list.files('R/')
      #   # invisible(sapply(paste0('R/', files.sources), source))"
      #   #           ),
      #   h3("Downloading the data"),
      #   tags$hr(),
      #   p("As described in the 0_DownloadData file, the health data from Brazil can be downloaded in many different ways. Here, it is downloaded with the help of the package microdatasus. The following code block will download the data for the year 2014 (which was chosen randomly)."),
      #   #   shinyAce::aceEditor(
      #   #     "brasil_malaria_2", mode="r", theme="tomorrow", readOnly=TRUE, height="13",
      #   #     value= "malariaData <- fetch_datasus(year_start = 2014, year_end = 2014, information_system = 'SINAN-MALARIA')"
      #   #   ),
      #   h3("Getting to know the Data"),
      #   h5("Variables"),
      #   p("There are a total of 50 variables. The variables names can be seen below:"),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_3", mode="r", theme="tomorrow", readOnly=TRUE, height="13",
      #   #             value= "colnames(malariaData)"
      #   #           ),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_4", mode="r", theme="tomorrow", readOnly=TRUE, height="130",
      #   #             value= "##  [1] 'TP_NOT'     'ID_AGRAVO'  'DT_NOTIFIC' 'SEM_NOT'    'NU_ANO'
      #   # ##  [6] 'SG_UF_NOT'  'ID_MUNICIP' 'ID_REGIONA' 'ID_UNIDADE' 'DT_SIN_PRI'
      #   # ## [11] 'SEM_PRI'    'ANO_NASC'   'NU_IDADE_N' 'CS_SEXO'    'CS_GESTANT'
      #   # ## [16] 'CS_RACA'    'CS_ESCOL_N' 'SG_UF'      'ID_MN_RESI' 'ID_RG_RESI'
      #   # ## [21] 'ID_PAIS'    'DT_INVEST'  'ID_OCUPA_N' 'CLASSI_FIN' 'AT_ATIVIDA'
      #   # ## [26] 'AT_LAMINA'  'AT_SINTOMA' 'TPAUTOCTO'  'COUFINF'    'COPAISINF'
      #   # ## [31] 'COMUNINF'   'LOC_INF'    'DEXAME'     'RESULT'     'PMM'
      #   # ## [36] 'PCRUZ'      'TRA_ESQUEM' 'DSTRAESQUE' 'DTRATA'     'NU_LOTE_I'
      #   # ## [41] 'DT_ENCERRA' 'DT_DIGITA'  'DT_TRANSUS' 'DT_TRANSDM' 'DT_TRANSSM'
      #   # ## [46] 'DT_TRANSRM' 'DT_TRANSRS' 'DT_TRANSSE' 'NU_LOTE_V'  'NU_LOTE_H'"
      #   #           ),
      #   p(HTML(paste0("The definition of each variable can be found in the ",
      #                 tags$a("official documentation", href="Workspace/Dictionary_Malaria_PT.pdf", target="_blank")," or ", tags$a("online", href="http://portalsinan.saude.gov.br/images/documentos/Agravos/Malaria/DIC_DADOS_Malaria_v5.pdf",target="_blank"), " in Portuguese, or in this ", tags$a("translated csv file", href="Workspace/Dictionary_Malaria_EN.csv", target="_blank"),". This file also contains the decodification for all numerical categories. A small overview of this file can be seen below:"))),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_5", mode="r", theme="tomorrow", readOnly=TRUE, height="36",
      #   #             value= "malariaVarDefPath <- file.path(getwd(), 'Workspace', 'Dictionary_Malaria_EN.csv')
      #   # malariaVarDef <- read.csv(malariaVarDefPath)
      #   # knitr::kable(malariaVarDef[14:20,1:5])"
      #   #           ),
      #   ### table
      #   tags$img(src="filter.png",width="20"),
      #   p("To avoid working with unnecessary data, it is useful to filter out the variables that will not be used. Below is a line of code on how to select only the needed variables."),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_6", mode="r", theme="tomorrow", readOnly=TRUE, height="24",
      #   #             value= "sel_var <- c('NU_IDADE_N','CS_SEXO', 'CS_GESTANT', 'CS_RACA', 'AT_LAMINA', 'AT_SINTOMA', 'DT_NOTIFIC', 'DT_SIN_PRI', 'DT_DIGITA', 'DEXAME', 'DTRATA', 'ID_MUNICIP',  'ID_MN_RESI',  'COMUNINF','RESULT')
      #   # malariaData <- malariaData %>% select(all_of(sel_var))"
      #   #           ),
      #   h3("Completeness of the data"),
      #   p("Some of these variables are mandatory to notify, others are not, which leads to incomplete datasets. The chart ", tags$b("NACountChart"), "  shows the the variables which have NA-values and the percentage of NAs they contain."),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_7", mode="r", theme="tomorrow", readOnly=TRUE, height="125",
      #   #             value= "# get count of NA for each variable
      #   # NACount <- malariaData %>% map(~mean(is.na(.)))
      #   # NACount <- data.frame(count=unlist(NACount),
      #   #                       var=names(NACount))

      #   # ggplot(NACount[NACount$count != 0, ], aes(x = reorder(var, count), y = count)) +
      #   #   geom_bar(stat = 'identity', width = 0.9, position = position_dodge(width = 5)) +
      #   #   ylab('Percentage of NAs in each column') +
      #   #   xlab('Variables') +
      #   #   coord_flip()"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_NAs-1.png"),
      #   p("On the contrary, it is also good to know what variables are complete."),
      #   #   shinyAce::aceEditor(
      #   #     "brasil_malaria_8", mode="r", theme="tomorrow", readOnly=TRUE, height="12",
      #   #     value= "NACount$var[NACount$count == 0]"
      #   #   ),
      #   ### result
      #   tags$img(src="filter.png",width="20"),
      #   p("To filter out variables which are (almost) completely empty, you can run the following lines."),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_9", mode="r", theme="tomorrow", readOnly=TRUE, height="24",
      #   #             value= "drop_variables <- NACount$var[NACount$count == 1]
      #   # malariaData <- malariaData[, !(names(malariaData) %in% drop_variables)]"
      #   #           ),
      #   h3("Exam Results"),
      #   p("The database distinguishes 10 different types/combinations of malaria:"),
      #   tags$ul(
      #     tags$li("Negative"),
      #     tags$li(tags$i("Falciparum")),
      #     tags$li(tags$i("F+Fg")),
      #     tags$li(tags$i("Vivax")),
      #     tags$li(tags$i("F+V")),
      #     tags$li(tags$i("V+Fg")),
      #     tags$li(tags$i("Fg")),
      #     tags$li(tags$i("Malariae")),
      #     tags$li(tags$i("F+M")),
      #     tags$li(tags$i("Ovale"))
      #   ),
      #   p("The ", tags$b("negative"), "  notification needs to be filtered (excluded) to obtain the total malaria cases because they are not cases as the exam result was negative. Also, we should exclude NAs."),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_10", mode="r", theme="tomorrow", readOnly=TRUE, height="255",
      #   #             value= "malariaData <- malariaData %>%
      #   #   mutate(RESULT = as.factor(case_when(RESULT == '1' ~ 'Negative',
      #   #                                       RESULT == '2' ~ 'Falciparum',
      #   #                                       RESULT == '3' ~ 'F+Fg',
      #   #                                       RESULT == '4' ~ 'Vivax',
      #   #                                       RESULT == '5' ~ 'F+V',
      #   #                                       RESULT == '6' ~ 'V+Fg',
      #   #                                       RESULT == '7' ~ 'Fg',
      #   #                                       RESULT == '8' ~ 'Malariae',
      #   #                                       RESULT == '9' ~ 'F+M',
      #   #                                       RESULT == '10' ~ 'Ovale')))

      #   # ggplot(malariaData, aes(x = RESULT, fill=RESULT)) +
      #   #   geom_bar() +
      #   #   annotate('text', x = Inf, y = Inf, hjust = 1, vjust = 1, size = 4,
      #   #            label = paste0(sum(is.na(malariaData$RESULT)), ' NA values'))+
      #   #   labs(title='Exam results during malaria cases in 2014',
      #   #        y='Count', x='Exam Result', fill='Exam Results') +
      #   #   geom_text(stat = 'count', position = position_stack(vjust = 0.5),
      #   #             aes(label = paste0(round((after_stat(count))/sum(after_stat(count)) * 100, 1), '%'),
      #   #                 x = RESULT))"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_Type-1.png"),
      #   p("However, generally, people only distinguish in 3 categories: ", tags$i("P. vivax"), "  and ", tags$i("P. falciparum"), "  and the mixed version ", tags$i("P+V"), " ."),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_11", mode="r", theme="tomorrow", readOnly=TRUE, height="205",
      #   #             value= "malariaData <- malariaData %>%
      #   #   mutate(RES_EXAM = as.factor(case_when(RESULT == 'Falciparum' | RESULT == 'F+Fg' | RESULT == 'Fg' | RESULT == 'F+M' ~ 'F',
      #   #                                         RESULT == 'Vivax' | RESULT == 'V+Fg' ~ 'V',
      #   #                                         RESULT == 'F+V'  ~  'V+F',
      #   #                                         RESULT == 'Malariae' | RESULT == 'Ovale' ~ 'other',
      #   #                                         RESULT == 'Negative' ~ 'Negative')))

      #   # ggplot(malariaData, aes(x = RES_EXAM, fill=RES_EXAM)) +
      #   #   geom_bar() +
      #   #   labs(title='Exam results during malaria cases in 2014',
      #   #        y='Count', x='Exam Result', fill='Exam Results') +
      #   #   annotate('text', x = Inf, y = Inf, hjust = 1, vjust = 1, size = 4,
      #   #            label = paste0(sum(is.na(malariaData$RES_EXAM)), ' NA values'))+
      #   #   geom_text(stat = 'count', position = position_stack(vjust = 0.5),
      #   #             aes(label = paste0(round((after_stat(count))/sum(after_stat(count)) * 100, 1), '%'),
      #   #                 x = RES_EXAM))"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/unnamed-chunk-2-1.png"),
      #   p(HTML(paste0("The majority of case are ", tags$i("Vivax")," (2.9%), followed by ", tags$i("Falciparum")," (2.9%). All other categories together make 100%. Fg is the gametocyte phase of the ", tags$i("P. falciparum")," life cycle."))),
      #   p(HTML(paste0("Below, the distribution of the most prevalent malaria can bee seen throughout the year on an epiweek time resolution. Note the ", tags$i("vivax")," and ", tags$i("falciparum")," cases are the combination between more than one ", tags$b("RESULT")," category."))),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_TypeTimeseries-1.png"),
      #   tags$img(src="filter.png",width="20"),
      #   p("To exclude cases with a negative test result, you can run the following lines"),
      #   #   shinyAce::aceEditor(
      #   #     "brasil_malaria_12", mode="r", theme="tomorrow", readOnly=TRUE, height="12",
      #   #     value= "malariaData <- malariaData[malariaData$RESULT != 'Negative',]"
      #   #   ),
      #   h3("Information on the Patients"),
      #   h5("Age of patients"),
      #   p(HTML(paste0("For malaria, the age of the patients can be derived from ", tags$b("NU_IDADE_N"),". ", tags$b("NU_IDADE_N"), " is codified:"))),
      #   tags$ol(
      #     tags$li("the first number indicates what “dimension” it is using. 1= Hour, 2= day, 3= month, 4= year."),
      #     tags$li("the last numbers indicate the age.")
      #   ),
      #   p("The age can be “decodified” with the command line below. This line of code also automatically removes all inconsistent ages, i.e. people over 120 years and people whose age was given in a unusual way (e.g. 84 months)."),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_13", mode="r", theme="tomorrow", readOnly=TRUE, height="200",
      #   #             value= "malariaData  <- malariaData %>%
      #   #   mutate(AGE = case_when(NU_IDADE_N < 120 ~ as.numeric(NU_IDADE_N), # assumes that non-codified data means that the age in years was given
      #   #                            NU_IDADE_N >= 120 & NU_IDADE_N < 1000 ~ NA_real_,
      #   #                            NU_IDADE_N >= 1000 & NU_IDADE_N < 2366 ~ 0,
      #   #                            NU_IDADE_N >= 2366 & NU_IDADE_N < 3000 ~ NA_real_,
      #   #                            NU_IDADE_N >= 3000 & NU_IDADE_N < 3013 ~ 0,
      #   #                            NU_IDADE_N >= 3013 & NU_IDADE_N < 4000 ~ NA_real_,
      #   #                            NU_IDADE_N >= 4000 & NU_IDADE_N < 4120 ~ as.numeric(NU_IDADE_N - 4000),
      #   #                            NU_IDADE_N >= 4120 ~ NA_real_,
      #   #                            TRUE ~ NA_real_))

      #   # ggplot(malariaData, aes(x = AGE))+
      #   #   geom_histogram(binwidth = 1, fill = 'lightblue',color='black', alpha = 0.7)+
      #   #   annotate('text', x = 100, y = Inf, label = paste0(sum(is.na(malariaData$AGE)), ' NA values'), hjust = 1, vjust = 1, size = 4)+
      #   #   labs(x='Age [years]', y='Count', title='Age distribution')+
      #   #   theme_light()"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_Age-1.png"),
      #   tags$img(src="filter.png",width="20"),
      #   p("Other datasets may include a date of birth, if provided, it can be used to corroborate the real age."),
      #   h3("Sex of the patients"),
      #   p(HTML(paste0("The sex of the patients is given by ", tags$b("CS_SEXO"),". A table and a barplot of its distribution can be seen below:"))),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_14", mode="r", theme="tomorrow", readOnly=TRUE, height="180",
      #   #             value= "malariaData <- malariaData %>%
      #   #   mutate(CS_SEXO = as.factor(case_when(CS_SEXO == 'F' ~ 'Female',
      #   #                                        CS_SEXO == 'M' ~ 'Male',
      #   #                                        CS_SEXO == 'I' ~ 'Ignored',
      #   #                                        TRUE ~ 'NA')))

      #   #  ggplot(malariaData, aes(x = CS_SEXO, fill=CS_SEXO)) +
      #   #   geom_bar() +
      #   #   labs(title='Sex distribution of malaria cases in 2015',
      #   #        x='Sex of the patient', y='Count', fill='Sex')+
      #   #   geom_text(stat = 'count', position = position_stack(vjust = 0.5),
      #   #             aes(label = paste0(round((after_stat(count))/sum(after_stat(count)) * 100, 1), '%'),
      #   #                 x = CS_SEXO)) +
      #   #   theme_light()"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_Sex%20plot-1.png"),
      #   h5("Pregnancy"),
      #   p(HTML(paste0("Another related variable is ", tags$b("CS_GESTANT"),", which indicates whether the patient is pregnant. Since only women below a certain age can get pregnant this is another way to check for inconsistencies."))),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_15", mode="r", theme="tomorrow", readOnly=TRUE, height="140",
      #   #             value= "pregnant <- malariaData %>%
      #   #   filter((CS_GESTANT == 1 | CS_GESTANT == 2 | CS_GESTANT ==3 | CS_GESTANT == 4)) %>%
      #   #   count()

      #   # mpreg <- malariaData %>%
      #   #   filter(CS_SEXO == 'M' & (CS_GESTANT == 1 | CS_GESTANT == 2 | CS_GESTANT ==3 | CS_GESTANT == 4)) %>%
      #   #   count()

      #   # pover50 <- malariaData %>%
      #   #   filter(AGE > 50 & (CS_GESTANT == 1 | CS_GESTANT == 2 | CS_GESTANT ==3 | CS_GESTANT == 4)) %>%
      #   #   count()"
      #   #           ),yAce::aceEditor(
      #   #             "brasil_malaria_15", mode="r", theme="tomorrow", readOnly=TRUE, height="140",
      #   #             value= "pregnant <- malariaData %>%
      #   #   filter((CS_GESTANT == 1 | CS_GESTANT == 2 | CS_GESTANT ==3 | CS_GESTANT == 4)) %>%
      #   #   count()

      #   # mpreg <- malariaData %>%
      #   #   filter(CS_SEXO == 'M' & (CS_GESTANT == 1 | CS_GESTANT == 2 | CS_GESTANT ==3 | CS_GESTANT == 4)) %>%
      #   #   count()

      #   # pover50 <- malariaData %>%
      #   #   filter(AGE > 50 & (CS_GESTANT == 1 | CS_GESTANT == 2 | CS_GESTANT ==3 | CS_GESTANT == 4)) %>%
      #   #   count()"
      #   #           ),
      #   tags$img(src="filter.png",width="20"),
      #   p("Out of 5 pregnant patients, there are 0 pregnant males and 0 pregnant women over the age of 50. Again, depending on the aim of the study, these patients could be excluded using the following line."),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_16", mode="r", theme="tomorrow", readOnly=TRUE, height="50",
      #   #             value= "malariaData <- malariaData %>%
      #   #   filter(!(CS_GESTANT %in% c('1', '2', '3', '4') & CS_SEXO == 'M') &
      #   #            !(CS_GESTANT %in% c('1', '2', '3', '4') & AGE > 50))"
      #   #           ),
      #   h5("Race of the patients"),
      #   p(HTML(paste0("The race of the patient is given by ", tags$b("CS_RACA"),". A barplot of its distribution can be seen below:"))),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_Race-1.png"),
      #   h3("Classifying the malaria cases"),
      #   p(HTML(paste0("Malaria can be detected either actively (when someone goes to doctor because of symptoms), passively (as protocol when one case is detected, people living in the same place are screened) or through LVC (Lamina de Verificaçao de Cura = cure thick blood smear verification). The variable ", tags$b("AT_LAMINA"),", shows exactly this."))),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_17", mode="r", theme="tomorrow", readOnly=TRUE, height="180",
      #   #             value= "malariaData <- malariaData %>%
      #   #     mutate(AT_LAMINA = as.factor(case_when(AT_LAMINA == 1 ~ 'Active',
      #   #                                        AT_LAMINA == 2 ~ 'Passive',
      #   #                                        AT_LAMINA == 3 ~ 'LVC',
      #   #                                        TRUE ~ 'NA')))
      #   # ggplot(malariaData, aes(x = AT_LAMINA, fill=AT_LAMINA)) +
      #   #   geom_bar() +
      #   #   labs(title='Type of detections of malaria cases in 2014',
      #   #        y='Count', x='Detection type', fill='Detection type')+
      #   #   geom_text(stat = 'count',
      #   #             aes(label = paste0(round((after_stat(count))/sum(after_stat(count)) * 100, 1), '%'),
      #   #                 x = AT_LAMINA),
      #   #             position = position_stack(vjust = 0.5)) +
      #   #   annotate('text', x = Inf, y = Inf, hjust = 1, vjust = 1, size = 4,
      #   #            label = paste0(sum(is.na(malariaData$AT_LAMINA)), ' NA values'))"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_Detection-1.png"),
      #   p("As can be seen, most cases (65.9%) are found actively and only 7.3% are passively."),
      #   h5("Symptoms"),
      #   p(HTML(paste0("For malaria, the variable ", tags$b("AT_SINTOMA")," makes the distinction whether there are symptoms present or not."))),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_18", mode="r", theme="tomorrow", readOnly=TRUE, height="160",
      #   #             value= "malariaData %>%
      #   #   mutate(AT_SINTOMA = as.factor(case_when(AT_SINTOMA== '1' ~ 'Yes',
      #   #                                           AT_SINTOMA == '2' ~ 'No',
      #   #                                           TRUE ~ 'NA'))) %>%
      #   #   ggplot(aes(x = AT_SINTOMA, fill=AT_SINTOMA)) +
      #   #   geom_bar() +
      #   #   labs(title='Presence of symptoms during malaria cases in 2014',
      #   #        y='Count', x='Presence of symptoms', fill='Presence of symptoms') +
      #   #   annotate('text', x = Inf, y = Inf, hjust = 1, vjust = 1, size = 4,
      #   #            label = paste0(sum(is.na(malariaData$AT_SINTOMA)), ' NA values'))+
      #   #   geom_text(stat = 'count', position = position_stack(vjust = 0.5),
      #   #             aes(label = paste0(round((after_stat(count))/sum(after_stat(count)) * 100, 1), '%'),
      #   #                 x = AT_SINTOMA))"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_Symptoms-1.png"),
      #   p("A clear majority of NA% malaria cases had symptoms."),
      #   h1("Timeline of malaria cases"),
      #   h3("Notification distribution throughout the year"),
      #   p(HTML(paste0("In the dataset, you can find many dates, one of the most important might be the notification date ", tags$b("DT_NOTIFIC"),". This is the first time that a potential malaria patient contacts the medical authorities. Below the annual distribution of notifications during 2014 can be seen. There is no clear seasonal variation but tended to concentrate cases during the summer season in Brazil."))),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_19", mode="r", theme="tomorrow", readOnly=TRUE, height="105",
      #   #             value= "malariaData %>%
      #   #   mutate(EPIWEEK = floor_date(DT_NOTIFIC, 'weeks')) %>%
      #   #   group_by(EPIWEEK) %>%
      #   #   summarise(Count = n()) %>%
      #   #   ggplot() +
      #   #   geom_line(aes(x = EPIWEEK, y = Count)) +
      #   #   scale_x_date(date_labels = '%m-%d', date_breaks = '1 week') +
      #   #   theme(axis.text.x = element_text(angle = 45, hjust = 1))"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/unnamed-chunk-3-1.png"),
      #   h3("Timeline of all other events"),
      #   p(HTML(paste0("First, symptoms occur (", tags$b("DT_SIN_TO_PRI"), " ). Once the doctor notifies a suspected malaria case (", tags$b("DT_NOTIFIC"), " ), it will be digitized (", tags$b("DT_DIGITA"), " ). The malaria case needs to be confirmed through an exam (", tags$b("DEXAME"), "), and if confirmed, treated (", tags$b("DTRATA"), " ). Below are boxplots for each of the events date."))),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_20", mode="r", theme="tomorrow", readOnly=TRUE, height="180",
      #   #             value= "malariaData <- malariaData %>%
      #   #   mutate(Symptoms = as.numeric(DT_SIN_PRI - DT_NOTIFIC),
      #   #          Digitalization = as.numeric(DT_DIGITA - DT_NOTIFIC),
      #   #          Exam = as.numeric(DEXAME - DT_NOTIFIC),
      #   #          Treatment = as.numeric(DTRATA - DT_NOTIFIC))

      #   # malariaData %>%
      #   #   select(Symptoms, Digitalization, Exam, Treatment) %>%
      #   #   gather(TYPE, DAYS) %>%
      #   #   ggplot(aes(x = TYPE, y = DAYS)) +
      #   #   geom_boxplot() +
      #   #   coord_cartesian(ylim = c(-100, 100)) +
      #   #   xlab('Event') +
      #   #   ylab('Days from the notification day')"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_Timeline-1.png"),
      #   p("The boxplot is able to visualize possible outliers:"),
      #   tags$ul(
      #     tags$li("The ", tags$b("first symptoms"), "  occur before the notification date, the vast majority of them in the 10 days prior to it. Symptoms that occur after the notification date or a long time before hte notification date may have to be removed."),
      #     tags$li("The ", tags$b("treatment"), " , ", tags$b("digitalization"), "  and ", tags$b("exam"), "  dates, must fall on or within the 60 days after the notification date. If they fall outside this range, they can be coonsidered outliers and may be removed.")
      #   ),
      #   h1("Mapping spatially"),
      #   h3("Notification, Residence & Probable Infection"),
      #   p(HTML(paste0("There is of course also spatial data in the data sets. Before diving in deeper it is necessary to download the shapefiles of Brazil municipalities. This can be done via the ", tags$i("geobr"), "  package. However, the municipality code given by geobr is one digit too long and has to be shortened to 6 digits."))),
      #   p("In total, the dataset refers to 3 different locations:"),
      #   tags$ul(
      #     tags$li("", tags$b("ID_MUNICIP"), "  is the municipality where the case is notified."),
      #     tags$li("", tags$b("ID_MN_RESI"), "  is the municipality of residence of the patient."),
      #     tags$li("", tags$b("COMUNINF"), "  is the municipality the patient probably got the infection.")
      #   ),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_21", mode="r", theme="tomorrow", readOnly=TRUE, height="70",
      #   #             value= "muni <- read_municipality(code_muni = 'all', year = 2014, showProgress = FALSE) %>%
      #   #   mutate(code_muni = str_sub(code_muni, end = 6)) %>%
      #   #   left_join(as.data.frame(table(malariaData$ID_MUNICIP, dnn = list('code_muni')), responseName = 'noti_muni')) %>%
      #   #   left_join(as.data.frame(table(malariaData$COMUNINF, dnn = list('code_muni')), responseName = 'infec_muni')) %>%
      #   #   left_join(as.data.frame(table(malariaData$ID_MN_RESI, dnn = list('code_muni')), responseName = 'resi_muni'))"
      #   #           ),
      #   p("Depending on what the aim of the study is, each of these variables can be important."),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_22", mode="r", theme="tomorrow", readOnly=TRUE, height="115",
      #   #             value= "cols <- c('green', 'yellow','orange','red', 'black') #change these as needed
      #   # breaks <- c(0, 10, 100, 1000, 10000, 100000) #change these as needed

      #   # ggplot(muni) +
      #   #   ggtitle('Extra-Amazon malaria per municipality of notification') +
      #   #   geom_sf( aes(fill = noti_muni), size = .15, show.legend = TRUE) +
      #   #   scale_fill_stepsn(breaks = breaks,
      #   #                     colours = cols,
      #   #                     values = scales::rescale(breaks))"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_plot-1.png"),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_23", mode="r", theme="tomorrow", readOnly=TRUE, height="80",
      #   #             value= "ggplot(muni) +
      #   #   ggtitle('Extra-Amazon malaria per municipality of probable infection') +
      #   #   geom_sf(aes(fill = infec_muni), size = .15, show.legend = TRUE)  +
      #   #   scale_fill_stepsn(breaks = breaks,
      #   #                     colours = cols,
      #   #                     values = scales::rescale(breaks))"
      #   #           ),
      #   #           tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_plot-2.png"),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_24", mode="r", theme="tomorrow", readOnly=TRUE, height="80",
      #   #             value= "ggplot(muni) +
      #   #   ggtitle('Extra-Amazon malaria per municipality of residence')+
      #   #   geom_sf( aes(fill = resi_muni), size = .15, show.legend = TRUE)  +
      #   #   scale_fill_stepsn(breaks = breaks,
      #   #                     colours = cols,
      #   #                     values = scales::rescale(breaks))"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_plot-3.png"),
      #   p(HTML(paste0("", tags$b("What did you find after see the maps?"), "  Take a look of the difference between the Extra-Amazon malaria by municipality of notification and probable infection. Almost all malaria notified in the Extra-Amazon region was acquired in the Amazon region. Some people live in the Amazon region were notified in the Extra-Amazon region."))),
      #   h3("Mapping types of Malaria"),
      #   p("If one wants to map them distinguishing by type, the following code can be used:"),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_25", mode="r", theme="tomorrow", readOnly=TRUE, height="80",
      #   #             value= "muni <- muni %>%
      #   #   left_join(as.data.frame(table(malariaData$ID_MUNICIP[malariaData$RES_EXAM == 'V'], dnn = list('code_muni')), responseName = 'vivax_muni')) %>%
      #   #   left_join(as.data.frame(table(malariaData$ID_MUNICIP[malariaData$RES_EXAM == 'F'], dnn = list('code_muni')), responseName = 'falci_muni')) %>%
      #   #   left_join(as.data.frame(table(malariaData$ID_MUNICIP[malariaData$RES_EXAM == 'V+F'], dnn = list('code_muni')), responseName = 'mixed_muni')) %>%
      #   #   left_join(as.data.frame(table(malariaData$ID_MUNICIP[malariaData$RES_EXAM == 'other'], dnn = list('code_muni')), responseName = 'other_muni'))

      #   # vivax_plot <- ggplot(muni) +
      #   #   geom_sf( aes(fill = vivax_muni), size = .15, show.legend = TRUE) +
      #   #   scale_fill_viridis_c() +
      #   #   labs(subtitle = paste0('Number of P. vivax cases in Brazil 2015'), size = 8) +
      #   #   theme_minimal()
      #   # vivax_plot"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_plotType-1.png"),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_26", mode="r", theme="tomorrow", readOnly=TRUE, height="80",
      #   #             value= "falci_plot <-  ggplot(muni) +
      #   #   geom_sf( aes(fill = falci_muni), size = .15, show.legend = TRUE) +
      #   #   scale_fill_viridis_c() +
      #   #   labs(subtitle=paste0('Number of P. falciparum cases in Brazil 2015'), size = 8) +
      #   #   theme_minimal()
      #   # falci_plot"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_plotType-2.png"),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_27", mode="r", theme="tomorrow", readOnly=TRUE, height="80",
      #   #             value= "mixed_plot <-  ggplot(muni) +
      #   #   geom_sf( aes(fill = mixed_muni), size = .15, show.legend = TRUE) +
      #   #   scale_fill_viridis_c() +
      #   #   labs(subtitle=paste0('Number of mixed cases in Brazil 2015'), size = 8) +
      #   #   theme_minimal()
      #   # mixed_plot"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_plotType-3.png"),
      #   h3("Calculating the incidence"),
      #   p(HTML(paste0("Sometimes, having the absolute values is helpful. But other times, the number of cases can be highly dependent on the number of inhabitants and then the incidence or other similar indicator is used. Another reason to use incidence is to make comparable the number of cases between areas and different times. Specifically for malaria, the analogous indicator, the Annual Parasite Index (API) is most common. This indicator is calculated by the number of malaria positive patients occurred in a specific time and place divided by the population per 1.000 inhabitants. This positive patients can be a new case or a relapse. Relapses are most common in malaria ", tags$i("vivax"), "  infection."))),
      #   p(HTML(paste0("For this, the population data needs to be loaded from [IBGE](https://www.ibge.gov.br/estatisticas/sociais/populacao/9103-estimativas-de-populacao.html?edicao=31451&t=resultados) either manually or using the local function “get_br_pop_data” (instructions can be viewed in 0_DownloadData.md)."))),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_28", mode="r", theme="tomorrow", readOnly=TRUE, height="80",
      #   #             value= "get_br_pop_data(2015, save=F)

      #   # muni <-  left_join(muni, pop_2015[c('code_muni','pop')], by='code_muni')
      #   # muni$pop <- as.numeric(muni$pop)"
      #   #           ),
      #   p("The incidence is then calculated by dividing the malaria cases by the population of each municipality and multiplication by 1000."),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_29", mode="r", theme="tomorrow", readOnly=TRUE, height="80",
      #   #             value= "muni$noti_inc <- muni$noti_muni / muni$pop*1000
      #   # muni$infec_inc <- muni$infec_muni / muni$pop*1000
      #   # muni$resi_inc <- muni$resi_muni / muni$pop*1000

      #   # breaks2 <- c(0, 5, 25, 50, 100, 250)
      #   # noti_inci_plot <- ggplot(muni) +
      #   #   ggtitle('Incidence of malaria notifications in 2015')+
      #   #   geom_sf( aes(fill = noti_inc), size = .15, show.legend = TRUE)  +
      #   #   scale_fill_stepsn(breaks = breaks2,
      #   #                     colours = cols,
      #   #                     values = scales::rescale(breaks2))
      #   # noti_inci_plot"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_Incidence-1.png"),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_30", mode="r", theme="tomorrow", readOnly=TRUE, height="80",
      #   #             value= "infe_inci_plot <- ggplot(muni) +
      #   #   ggtitle('Incidence of probable malaria infections in 2015')+
      #   #   geom_sf(aes(fill = infec_inc), size = .15, show.legend = TRUE)  +
      #   #   scale_fill_stepsn(breaks = breaks2,
      #   #                     colours = cols,
      #   #                     values = scales::rescale(breaks2))
      #   # infe_inci_plot"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_Incidence-2.png"),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_31", mode="r", theme="tomorrow", readOnly=TRUE, height="80",
      #   #             value= "resi_inci_plot <- ggplot(muni) +
      #   #   ggtitle('Incidence of residents with malaria in 2015')+
      #   #   geom_sf(aes(fill = resi_inc), size = .15, show.legend = TRUE)  +
      #   #   scale_fill_stepsn(breaks = breaks2,
      #   #                     colours = cols,
      #   #                     values = scales::rescale(breaks2))
      #   # resi_inci_plot"
      #   #           ),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_Incidence-3.png"),
      #   p("If one wants to know the incidence depending on the malaria type:"),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_32", mode="r", theme="tomorrow", readOnly=TRUE, height="130",
      #   #             value= "muni$vivax_inc <- muni$vivax_muni / muni$pop*1000
      #   # muni$falci_inc <- muni$falci_muni / muni$pop*1000
      #   # muni$mixed_inc <- muni$mixed_muni / muni$pop*1000

      #   # vivax_inci_plot <- ggplot(muni) +
      #   #   geom_sf(aes(fill = vivax_inc), size = .15, show.legend = TRUE) +
      #   #   scale_fill_viridis_c() +
      #   #   labs(subtitle = paste0('Vivax incidence in Brazil 2015'), size = 8) +
      #   #   theme_minimal()
      #   # vivax_inci_plot"
      #   #           ),
      #   #           tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_TypeIncidence-1.png"),
      #   #           shinyAce::aceEditor(
      #   #             "brasil_malaria_33", mode="r", theme="tomorrow", readOnly=TRUE, height="130",
      #   #             value= "falci_inci_plot<- ggplot(muni) +
      #   #   geom_sf( aes(fill = falci_inc), size = .15, show.legend = TRUE) +
      #   #   scale_fill_viridis_c()+
      #   #   labs(subtitle = paste0('Falciparum incidence in Brazil in 2015'), size = 8) +
      #   #   theme_minimal()
      #   # falci_inci_plot"
      #   #           ),
      #   #           tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_TypeIncidence-2.png"),
      #   #           shinyAce::aceEditor( "brasil_malaria_34", mode="r", theme="tomorrow",
      #   #                                readOnly=TRUE, height="70",
      #   #             value= "mixed_inci_plot<- ggplot(muni) +
      #   #   geom_sf( aes(fill = mixed_inc), size = .15, show.legend = TRUE) +
      #   #   scale_fill_viridis_c()+
      #   #   labs(subtitle = paste0('Mixed incidence in Brazil in 2015'), size = 8) +
      #   #   theme_minimal()
      #   # mixed_inci_plot"),
      #   tags$img(src="1a_MalariaData_files/figure-gfm/Malaria_TypeIncidence-3.png")
      # )
    # )
  )
}

### END
