```{r}
#| label: load packages
#| echo: false

library(here) # A Simpler Way to Find Your Files Posit RPSM v1.0.1
library(readxl) # Read Excel Files Posit RPSM v1.4.3
library(tibble) # Simple Data Frames Posit RPSM v3.2.1
library(fs) # Cross-Platform File System Operations Based on 'libuv' Posit RPSM v1.6.5
library(rmarkdown)  # Dynamic Documents for R Posit RPSM v2.28
library(yaml) # Methods to Convert R Data to YAML and Back Posit RPSM v2.3.10
library(quarto) # R Interface to 'Quarto' Markdown Publishing System Posit RPSM v1.4.4
library(sessioninfo) # R Session Information Posit RPSM v1.2.2
library(dplyr) # A Grammar of Data Manipulation Posit RPSM v1.1.4
library(tidyr) # Tidy Messy Data Posit RPSM v1.3.1
library(forcats) # Tools for Working with Categorical Variables (Factors) Posit RPSM v1.0.0
library(glue) # Interpreted String Literals Posit RPSM v1.8.0
library(plotly) # Create Interactive Web Graphics via 'plotly.js' Posit RPSM v4.10.4
library(htmltools) # Tools for HTML Posit RPSM v0.5.8.1
library(reactable) # Interactive Data Tables for R Posit RPSM v0.4.4
library(crosstalk) # Inter-Widget Interactivity for HTML Widgets Posit RPSM v1.2.1
library(fontawesome) # Easily Work with 'Font Awesome' Icons Posit RPSM v0.5.2

```


```{r}
#| label: load-data
#| message: false

birth_data <- readxl::read_excel(
  path = here::here(
    "data",
    "Live-Births By Sex And Ethnic Group, Monthly.xlsx"
  )
)

fertility_rate_data <- readxl::read_excel(
  path = here::here(
    "data",
    "Fertility Rate By Ethnic Group, Yearly.xlsx"
  )
)
```


```{r}
#| label: prep-data

fertility_rate_data_year <- fertility_rate_data |>
  tidyr::pivot_longer(
    cols = -c("Ethnicity"),
    names_to = c("Year"),
    values_to = "Total_Fertility_Rate_Per_Female"
  ) |>
  dplyr::mutate(
    Ethnicity = dplyr::case_when(
      .data[["Ethnicity"]] == "Chinese (Per Female)" ~ "Chinese",
      .data[["Ethnicity"]] == "Malays (Per Female)" ~ "Malays",
      .data[["Ethnicity"]] == "Indians (Per Female)" ~ "Indians",
      .data[["Ethnicity"]] == "All (Per Female)" ~ "Total*",
    ),
    Ethnicity = forcats::fct_relevel(
      .data[["Ethnicity"]],
      c("Chinese", "Malays", "Indians", "Total*")
    )
  ) |>
  dplyr::filter(
    .data[["Year"]] >= 1980
  )

birth_data_long <- birth_data |>
  tidyr::pivot_longer(
    cols = -c("Ethnicity", "Gender"),
    names_to = c("Year", "Month"),
    names_pattern = "(\\d{4})(\\w{3})",
    values_to = "count"
  ) |>
  dplyr::mutate(
    Ethnicity = forcats::fct_relevel(
      .data[["Ethnicity"]],
      c("Chinese", "Malays", "Indians", "Others")
    )
  )

birth_data_both_gender <- birth_data_long |>
  dplyr::summarise(
    total_live_birth = sum(.data[["count"]], na.rm = TRUE),
    .by = c("Ethnicity", "Year", "Gender")
  ) |>
  dplyr::filter(
    .data[["Year"]] >= 1980 & .data[["Gender"]] == "All"
  )

birth_data_male <- birth_data_long |>
  dplyr::summarise(
    total_live_birth = sum(.data[["count"]], na.rm = TRUE),
    .by = c("Ethnicity", "Year", "Gender")
  ) |>
  dplyr::filter(
    .data[["Year"]] >= 1980 & .data[["Gender"]] == "Male"
  )

birth_data_female <- birth_data_long |>
  dplyr::summarise(
    total_live_birth = sum(.data[["count"]], na.rm = TRUE),
    .by = c("Ethnicity", "Year", "Gender")
  ) |>
  dplyr::filter(
    .data[["Year"]] >= 1980 & .data[["Gender"]] == "Female"
  )

birth_data_for_display <- dplyr::bind_rows(
  birth_data_both_gender,
  birth_data_male,
  birth_data_female
)

```

# Fertility Rate {orientation="rows" scrolling="true"}

## Row - 2023 Fertility Value Boxes

```{r}
#| label: 2023 Fertility Rate by Ethnicity Total Box
#| content: valuebox
#| title: "2023 Fertility Rate (Total*)"

fertility_rate_2023 <- fertility_rate_data_year |>
  dplyr::filter(.data[["Year"]] == 2023) |>
  dplyr::filter(.data[["Ethnicity"]] == "Total*") |>
  dplyr::pull(.data[["Total_Fertility_Rate_Per_Female"]])

list(
  icon = "person-standing-dress",
  color = "#b67e54",
  value = fertility_rate_2023
)
```

```{r}
#| label: 2023 Fertility Rate by Ethnicity Chinese Box
#| content: valuebox
#| title: "2023 Fertility Rate (Chinese)"

fertility_rate_2023 <- fertility_rate_data_year |>
  dplyr::filter(.data[["Year"]] == 2023) |>
  dplyr::filter(.data[["Ethnicity"]] == "Chinese") |>
  dplyr::pull(.data[["Total_Fertility_Rate_Per_Female"]])

list(
  icon = "person-standing-dress",
  color = "#efb9e7",
  value = fertility_rate_2023
)
```

```{r}
#| label: 2023 Fertility Rate by Ethnicity Malay Box
#| content: valuebox
#| title: "2023 Fertility Rate (Malays)"

fertility_rate_2023 <- fertility_rate_data_year |>
  dplyr::filter(.data[["Year"]] == 2023) |>
  dplyr::filter(.data[["Ethnicity"]] == "Malays") |>
  dplyr::pull(.data[["Total_Fertility_Rate_Per_Female"]])

list(
  icon = "person-standing-dress",
  color = "#90ee90",
  value = fertility_rate_2023
)
```


```{r}
#| label: 2023 Fertility Rate by Ethnicity Indian Box
#| content: valuebox
#| title: "2023 Fertility Rate (Indians)"

fertility_rate_2023 <- fertility_rate_data_year |>
  dplyr::filter(.data[["Year"]] == 2023) |>
  dplyr::filter(.data[["Ethnicity"]] == "Indians") |>
  dplyr::pull(.data[["Total_Fertility_Rate_Per_Female"]])

list(
  icon = "person-standing-dress",
  color = "#c5bce0",
  value = fertility_rate_2023
)
```

## Row - Fertility Rate Plot and Table

### Column - Fertility Rate Plot

```{r}
#| label: Total Fertility Rate by Ethnicity Plot
#| title: ""

# For the hover text
text_input <- glue::glue(
   "{fertility_rate_data_year[['Ethnicity']]}: {format(fertility_rate_data_year[['Total_Fertility_Rate_Per_Female']], big.mark = ",", digits = 2)}"
)

plot <- plotly::plot_ly() |>
  plotly::add_trace(
    data = fertility_rate_data_year,
    x = fertility_rate_data_year[["Year"]],
    y = fertility_rate_data_year[["Total_Fertility_Rate_Per_Female"]],
    color = fertility_rate_data_year[["Ethnicity"]],
    colors = c(Chinese = "#efb9e7",
               Malays = "#90ee90",
               Indians = "#c5bce0",
               `Total*` = "#b67e54"),
    type = "scatter",
    mode = "lines+markers",
    marker = list(
      size = 10,
      line = list(color = "black", width = 1.5)
    ),
    linetype = fertility_rate_data_year[["Ethnicity"]],
    linetypes = c(Chinese = "solid",
                  Malays = "solid",
                  Indians = "solid",
                  `Total*` = "solid"),
    line = list(
      width = 5
    ),
    name = fertility_rate_data_year[["Ethnicity"]],
    text = text_input,
    hovertemplate = '%{text}<extra></extra>'
  ) |>
  plotly::layout(
    title = list(text = "<b>Resident Total Fertility Rate by Ethnicity<b>" ,
                 x = 0.5,
                 y = 1,
                 pad = list(l = 5, r = 5, b = 5, t = 20),
                 xanchor = 'center',
                 font = list(size = 20)),
    xaxis = list(title = "",
                 titlefont = list(size = 10),
                 tickfont = list(size = 12),
                 tickangle = -30,
                 gridcolor = "#eff5ee",
                 showgrid = TRUE,
                 showticklabels = TRUE,
                 tickcolor = "",
                 ticks = "",
                 zeroline = FALSE,
                 rangeslider = list(thickness = 0.05),
                 autorange = TRUE,
                 automargin = TRUE,
                 fixedrange = FALSE),
    yaxis = list(title = "",
                 titlefont = list(size = 10),
                 tickfont = list(size = 12),
                 gridcolor = "#c8cdc6",
                 showgrid = TRUE,
                 showline = FALSE,
                 showticklabels = TRUE,
                 tickcolor = "",
                 ticks = "",
                 zeroline = TRUE,
                 range = list(0, 3),
                 rangemode = "tozero",
                 autorange = FALSE,
                 automargin = TRUE,
                 fixedrange = TRUE),
    hovermode = "x unified",
    legend = list(
      title = list(text = "Ethnicity"),
      orientation = 'h',
      # Centered at x axis
      xanchor = "center",
      x = 0.5,
      # Place on the top
      y = 1,
      font = list(size = 14)
    ),
    autosize = TRUE,
    plot_bgcolor = "#eff5ee",
    paper_bgcolor = "#eff5ee",
    margin = list(l = 10, r = 10, b = 10, t = 50, pad = 10)
  ) |>
  plotly::add_annotations(
    x = 0,
    y = 1,
    xref = "paper",
    yref = "paper",
    yanchor = "bottom",
    text = "Total Fertility Rate\nPer Female",
    showarrow = FALSE,
    font = list(size = 15)
  ) |>
  plotly::add_annotations(
    x = 0,
    y = 0,
    xref = "paper",
    yref = "paper",
    text = "*\tIncludes the ethnic group 'Others'",
    showarrow = FALSE,
    font = list(size = 10)
  )

plot
```

### Column - Fertility Rate Table

```{r}
#| label: Total Fertility Rate by Ethnicity Table
#| title: "𝄜 Total Fertility Rate Data"

fertility_rate_data_year <- fertility_rate_data_year |>
  dplyr::mutate(
    Year = as.numeric(.data[["Year"]])
  ) |>
  dplyr::rename(
    `Fertility Rate Per Female` = "Total_Fertility_Rate_Per_Female"
  )

data <- crosstalk::SharedData$new(fertility_rate_data_year)

htmltools::div(
  style = "display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.75rem;",
  htmltools::div(
    crosstalk::filter_select(
      id = "Ethnicity",
      label = "Ethnicity",
      sharedData = data,
      group = ~Ethnicity,
      allLevels = TRUE),
    crosstalk::filter_slider(
      id = "Year",
      label = "Year",
      sharedData = data,
      column = "Year"),
    crosstalk::filter_slider(
      id = "Fertility Rate Per Female",
      label = "Fertility Rate Per Female",
      sharedData = data,
      column = "Fertility Rate Per Female",
      width = "100%")
  ),
  htmltools::div(
    style = "grid-column: span 3;",
    htmltools::browsable(
      htmltools::tagList(
        reactable::reactable(data, minRows = 10, elementId = "tfr-table", paginationType = "jump"),
        htmltools::tags$button("Download as CSV", onclick = "Reactable.downloadDataCSV('tfr-table')")
      )
    )
  )
)

```

# Live Birth {orientation="rows" scrolling="true"}

## Row - Live Birth Plot and Table

### Column - Live Birth Plot {.tabset}

```{r}
#| label: Total Live Birth by Ethnicity Plot
#| title: "🙋🏻‍♀ 🙋🏻‍♂ All"

# For the hover text
text_input <- glue::glue(
   "{birth_data_both_gender[['Ethnicity']]}: {birth_data_both_gender[['total_live_birth']]}"
)

plot <- plotly::plot_ly() |>
  plotly::add_trace(
    data = birth_data_both_gender,
    x = birth_data_both_gender[["Year"]],
    y = birth_data_both_gender[["total_live_birth"]],
    color = birth_data_both_gender[["Ethnicity"]],
    colors = c(Chinese = "#efb9e7",
               Malays = "#90ee90",
               Indians = "#c5bce0",
               Others = "#b67e54"),
    type = "scatter",
    mode = "lines+markers",
    marker = list(
      size = 10,
      line = list(color = "black", width = 1.5)
    ),
    line = list(
      width = 5
    ),
    linetype = birth_data_both_gender[["Ethnicity"]],
    linetypes = c(Chinese = "solid",
                  Malays = "solid",
                  Indians = "solid",
                  Others = "solid"),
    name = birth_data_both_gender[["Ethnicity"]],
    text = text_input,
    hovertemplate = '%{text}<extra></extra>'
  ) |>
  plotly::layout(
    title = list(text = "<b>Resident Total Live Birth by Ethnicity<b>" ,
                 x = 0.5,
                 y = 1,
                 pad = list(l = 5, r = 5, b = 5, t = 20),
                 xanchor = 'center',
                 font = list(size = 20)),
    xaxis = list(title = "",
                 titlefont = list(size = 10),
                 tickfont = list(size = 12),
                 tickangle = -30,
                 gridcolor = "#eff5ee",
                 showgrid = TRUE,
                 showticklabels = TRUE,
                 tickcolor = "",
                 ticks = "",
                 zeroline = FALSE,
                 rangeslider = list(thickness = 0.05),
                 automargin = TRUE,
                 autorange = TRUE,
                 fixedrange = FALSE),
    yaxis = list(title = "",
                 titlefont = list(size = 10),
                 tickfont = list(size = 12),
                 gridcolor = "#c8cdc6",
                 showgrid = TRUE,
                 showline = FALSE,
                 showticklabels = TRUE,
                 tickcolor = "",
                 ticks = "",
                 zeroline = TRUE,
                 rangemode = "tozero",
                 automargin = TRUE,
                 autorange = TRUE,
                 fixedrange = FALSE),
    hovermode = "x unified",
    legend = list(
      title = list(text = "Ethnicity"),
      orientation = 'h',
      # Centered at x axis
      xanchor = "center",
      x = 0.5,
      # Place on the top
      y = 1,
      font = list(size = 14)
    ),
    plot_bgcolor = "#eff5ee",
    paper_bgcolor = "#eff5ee",
    margin = list(l = 10, r = 10, b = 10, t = 50, pad = 10)
  ) |>
  plotly::add_annotations(
    x = 0,
    y = 1,
    xref = "paper",
    yref = "paper",
    yanchor = "bottom",
    text = "Total Live Birth",
    showarrow = FALSE,
    font = list(size = 15)
  )

plot
```

```{r}
#| label: Total Male Live Birth by Ethnicity Plot
#| title: "🙋🏻‍♂ Male"

# For the hover text
text_input <- glue::glue(
   "{birth_data_male[['Ethnicity']]}: {birth_data_male[['total_live_birth']]}"
)

plot <- plotly::plot_ly() |>
  plotly::add_trace(
    data = birth_data_male,
    x = birth_data_male[["Year"]],
    y = birth_data_male[["total_live_birth"]],
    color = birth_data_male[["Ethnicity"]],
    colors = c(Chinese = "#efb9e7",
               Malays = "#90ee90",
               Indians = "#c5bce0",
               Others = "#b67e54"),
    type = "scatter",
    mode = "lines+markers",
    marker = list(
      size = 10,
      line = list(color = "black", width = 1.5)
    ),
    line = list(
      width = 5
    ),
    linetype = birth_data_male[["Ethnicity"]],
    linetypes = c(Chinese = "solid",
                  Malays = "solid",
                  Indians = "solid",
                  Others = "solid"),
    name = birth_data_male[["Ethnicity"]],
    text = text_input,
    hovertemplate = '%{text}<extra></extra>'
  ) |>
  plotly::layout(
    title = list(text = "<b>Resident Male Live Birth by Ethnicity<b>" ,
                 x = 0.5,
                 y = 1,
                 pad = list(l = 5, r = 5, b = 5, t = 20),
                 xanchor = 'center',
                 font = list(size = 20)),
    xaxis = list(title = "",
                 titlefont = list(size = 10),
                 tickfont = list(size = 12),
                 tickangle = -30,
                 gridcolor = "#eff5ee",
                 showgrid = TRUE,
                 showticklabels = TRUE,
                 tickcolor = "",
                 ticks = "",
                 zeroline = FALSE,
                 rangeslider = list(thickness = 0.05),
                 autorange = TRUE,
                 fixedrange = FALSE),
    yaxis = list(title = "",
                 titlefont = list(size = 10),
                 tickfont = list(size = 12),
                 gridcolor = "#c8cdc6",
                 showgrid = TRUE,
                 showline = FALSE,
                 showticklabels = TRUE,
                 tickcolor = "",
                 ticks = "",
                 zeroline = TRUE,
                 rangemode = "tozero",
                 autorange = TRUE,
                 fixedrange = FALSE),
    hovermode = "x unified",
    legend = list(
      title = list(text = "Ethnicity"),
      orientation = 'h',
      # Centered at x axis
      xanchor = "center",
      x = 0.5,
      # Place on the top
      y = 1,
      font = list(size = 14)
    ),
    plot_bgcolor = "#eff5ee",
    paper_bgcolor = "#eff5ee",
    margin = list(l = 10, r = 10, b = 10, t = 50, pad = 10)
  ) |>
  plotly::add_annotations(
    x = 0,
    y = 1,
    xref = "paper",
    yref = "paper",
    yanchor = "bottom",
    text = "Total Male Live Birth",
    showarrow = FALSE,
    font = list(size = 15)
  )

plot
```

```{r}
#| label: Total Female Live Birth by Ethnicity Plot
#| title: "🙋🏻‍♀ Female"

# For the hover text
text_input <- glue::glue(
   "{birth_data_female[['Ethnicity']]}: {birth_data_female[['total_live_birth']]}"
)

plot <- plotly::plot_ly() |>
  plotly::add_trace(
    data = birth_data_female,
    x = birth_data_female[["Year"]],
    y = birth_data_female[["total_live_birth"]],
    color = birth_data_female[["Ethnicity"]],
    colors = c(Chinese = "#efb9e7",
               Malays = "#90ee90",
               Indians = "#c5bce0",
               Others = "#b67e54"),
    type = "scatter",
    mode = "lines+markers",
    marker = list(
      size = 10,
      line = list(color = "black", width = 1.5)
    ),
    line = list(
      width = 5
    ),
    linetype = birth_data_female[["Ethnicity"]],
    linetypes = c(Chinese = "solid",
                  Malays = "solid",
                  Indians = "solid",
                  Others = "solid"),
    name = birth_data_female[["Ethnicity"]],
    text = text_input,
    hovertemplate = '%{text}<extra></extra>'
  ) |>
  plotly::layout(
    title = list(text = "<b>Resident Female Live Birth by Ethnicity<b>" ,
                 x = 0.5,
                 y = 1,
                 pad = list(l = 5, r = 5, b = 5, t = 20),
                 xanchor = 'center',
                 font = list(size = 20)),
    xaxis = list(title = "",
                 titlefont = list(size = 10),
                 tickfont = list(size = 12),
                 tickangle = -30,
                 gridcolor = "#eff5ee",
                 showgrid = TRUE,
                 showticklabels = TRUE,
                 tickcolor = "",
                 ticks = "",
                 zeroline = FALSE,
                 rangeslider = list(thickness = 0.05),
                 autorange = TRUE,
                 fixedrange = FALSE),
    yaxis = list(title = "",
                 titlefont = list(size = 10),
                 tickfont = list(size = 12),
                 gridcolor = "#c8cdc6",
                 showgrid = TRUE,
                 showline = FALSE,
                 showticklabels = TRUE,
                 tickcolor = "",
                 ticks = "",
                 zeroline = TRUE,
                 rangemode = "tozero",
                 autorange = TRUE,
                 fixedrange = FALSE),
    hovermode = "x unified",
    legend = list(
      title = list(text = "Ethnicity"),
      orientation = 'h',
      # Centered at x axis
      xanchor = "center",
      x = 0.5,
      # Place on the top
      y = 1,
      font = list(size = 14)
    ),
    plot_bgcolor = "#eff5ee",
    paper_bgcolor = "#eff5ee",
    margin = list(l = 10, r = 10, b = 10, t = 50, pad = 10)
  ) |>
  plotly::add_annotations(
    x = 0,
    y = 1,
    xref = "paper",
    yref = "paper",
    yanchor = "bottom",
    text = "Total Female Live Birth",
    showarrow = FALSE,
    font = list(size = 15)
  )

plot
```

### Column - Live Birth Table

```{r}
#| label: Total Birth Data by Ethnicity Table
#| title: "𝄜 Total Birth Data"

birth_data_for_display <- birth_data_for_display |>
  dplyr::mutate(
    Year = as.numeric(.data[["Year"]])
  ) |>
  dplyr::rename(
    `Total Live Birth` = "total_live_birth"
  ) |>
  dplyr::relocate(
    "Gender",
    .after = "Ethnicity"
  )

data <- crosstalk::SharedData$new(birth_data_for_display)

htmltools::div(
  style = "display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.75rem;",
  htmltools::div(
    crosstalk::filter_select(
      id = "Ethnicity",
      label = "Ethnicity",
      sharedData = data,
      group = ~Ethnicity,
      allLevels = TRUE),
    crosstalk::filter_checkbox(
      id = "Gender",
      label = "Gender",
      sharedData = data,
      group = ~Gender,
      allLevels = TRUE),
    crosstalk::filter_slider(
      id = "Year",
      label = "Year",
      sharedData = data,
      column = "Year"),
    crosstalk::filter_slider(
      id = "Total Live Birth",
      label = "Total Live Birth",
      sharedData = data,
      column = "Total Live Birth",
      width = "100%")
  ),
  htmltools::div(
    style = "grid-column: span 3;",
    htmltools::browsable(
      htmltools::tagList(
        reactable::reactable(data, minRows = 10, elementId = "birth-table", paginationType = "jump"),
        htmltools::tags$button("Download as CSV", onclick = "Reactable.downloadDataCSV('birth-table')")
      )
    )
  )
)

```


# About {orientation="columns" scrolling="true"}

## Column - About the Dashboard {width="60%"}

::: {.card title="📊 About The Dashboard"}

This dashboard is built with [Quarto Dashboards](https://quarto.org/docs/dashboards/){target="_blank"}. It is based on the [Fertility Dashboard](https://www.singstat.gov.sg/find-data/search-by-theme/population/births-and-fertility/visualising-data/fertility-dashboard){target="_blank"} from [Department of Statistics Singapore](https://www.singstat.gov.sg/){target="_blank"}.

If you want to conduct your own analysis, see the following resources:

+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Resource                            | Link                                                                                                                                                                                              |
+=====================================+===================================================================================================================================================================================================+
| Births and Fertility Data           | [<i class='bi bi-globe' style='color:#000000;'></i> Website](https://www.singstat.gov.sg/find-data/search-by-theme/population/births-and-fertility/latest-data){target="_blank"}                  |
| Department of Statistics Singapore  |                                                                                                                                                                                                   |
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Fertility Rate By Ethnic Group,     | [<i class='bi bi-globe' style='color:#000000;'></i> Website](https://data.gov.sg/datasets/d_e39eeaeadb571c0d0725ef1eec48d166/view){target="_blank"}                                               |
| Yearly from                         |                                                                                                                                                                                                   |
| [data.gov.sg](https://data.gov.sg/) |                                                                                                                                                                                                   |
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Live-Births By Sex And Ethnic       | [<i class='bi bi-globe' style='color:#000000;'></i> Website](https://data.gov.sg/datasets/d_d05c760928eb5eaa58006d83462b834e/view){target="_blank"}                                               |
| Group, Monthly from                 |                                                                                                                                                                                                   |
| [data.gov.sg](https://data.gov.sg/) |                                                                                                                                                                                                   |
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Fertility Rate By Ethnic Group,     | [<i class='bi bi-file-earmark-excel-fill' style='color:#108445'></i> Fertility Rate By Ethnic Group, Yearly.xlsx](data/Fertility Rate By Ethnic Group, Yearly.xlsx){target="_blank"}              |
| Yearly till 2023 in Excel           |                                                                                                                                                                                                   |
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Live-Births By Sex And Ethnic       | [<i class='bi bi-file-earmark-excel-fill' style='color:#108445'></i> Live-Births By Sex And Ethnic Group, Monthly.xlsx](data/Live-Births By Sex And Ethnic Group, Monthly.xlsx){target="_blank"}  |
| Group, Monthly till Dec 2023        |                                                                                                                                                                                                   |
| in Excel                            |                                                                                                                                                                                                   |
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Quarto script to create Dashboard   | [<i class='bi bi-file-code-fill' style='color:#77acdf;'></i> Quarto Script](index.qmd){target="_blank"}                                                                                           |
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Github repository                   | [<i class='bi bi-github' style='color:#000000;'></i> Source code](https://github.com/JauntyJJS/fertility_dashboard){target="_blank"}                                                              |
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Quarto Resources from               | [<i class='bi bi-github' style='color:#000000;'></i> Resources](https://github.com/ivelasq/2024-07-18_quarto-dashboards){target="_blank"}                                                         |
| Isabella Velásquez                  |                                                                                                                                                                                                   |
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Quarto Tutorials from               | [<i class='bi bi-youtube' style='color:#ff0034;'></i> 1: Hello, Dashboards!](https://www.youtube.com/watch?v=HW7QbqI4fH0){target="_blank"}<br>                                                    |
| Mine Çetinkaya-Rundel               | [<i class='bi bi-youtube' style='color:#ff0034;'></i> 2: Components](https://www.youtube.com/watch?v=KdsQgwaY950){target="_blank"}<br>                                                            |
|                                     | [<i class='bi bi-youtube' style='color:#ff0034;'></i> 3: Theming and Styling](https://www.youtube.com/watch?v=NigWSB-jG4Y){target="_blank"}                                                       |
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Births And Fertility Rates, Annual and Live-Births By Sex And Ethnic Group data were accessed on 25 November 2024 from <https://data.gov.sg/>{target="_blank"}. Data is made available under the terms of [Singapore Open Data Licence version 1.0](https://data.gov.sg/open-data-licence){target="_blank"}

Made by Jeremy Selva [`r fontawesome::fa(name = "linkedin", fill = "#0077ac")`](https://www.linkedin.com/in/jeremy-selva-085b9112a/){target="_blank"} <br> @JauntyJJS [`r fontawesome::fa(name = "github", fill = "#000000")`](https://github.com/JauntyJJS){target="_blank"} [`r fontawesome::fa(name = "fab fa-square-x-twitter", fill = "#000000")`](https://twitter.com/JauntyJJS){target="_blank"} [`r fontawesome::fa(name = "bluesky", fill = "#1084ff")`](https://bsky.app/profile/jauntyjjs.bsky.social){target="_blank"} [<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5f53e7;overflow:visible;position:relative;"><path d="M433 179.1c0-97.2-63.7-125.7-63.7-125.7-62.5-28.7-228.6-28.4-290.5 0 0 0-63.7 28.5-63.7 125.7 0 115.7-6.6 259.4 105.6 289.1 40.5 10.7 75.3 13 103.3 11.4 50.8-2.8 79.3-18.1 79.3-18.1l-1.7-36.9s-36.3 11.4-77.1 10.1c-40.4-1.4-83-4.4-89.6-54a102.5 102.5 0 0 1 -.9-13.9c85.6 20.9 158.7 9.1 178.8 6.7 56.1-6.7 105-41.3 111.2-72.9 9.8-49.8 9-121.5 9-121.5zm-75.1 125.2h-46.6v-114.2c0-49.7-64-51.6-64 6.9v62.5h-46.3V197c0-58.5-64-56.6-64-6.9v114.2H90.2c0-122.1-5.2-147.9 18.4-175 25.9-28.9 79.8-30.8 103.8 6.1l11.6 19.5 11.6-19.5c24.1-37.1 78.1-34.8 103.8-6.1 23.7 27.3 18.4 53 18.4 175z"/></svg>](https://fosstodon.org/@JauntyJJS){target="_blank"}

:::

## Column - R Session and Packages Used {width="40%"}

```{r}
#| label: R Package Used
#| title: "📦 R Packages Used"

get_r_package_info <- function() {

  r_package_table <- sessioninfo::package_info()
  rownames(r_package_table) <- NULL

  r_package_table <- r_package_table |>
    tibble::as_tibble() |>
    dplyr::mutate(
      version = ifelse(is.na(r_package_table$loadedversion),
                       r_package_table$ondiskversion,
                       r_package_table$loadedversion)) |>
    dplyr::filter(.data[["attached"]] == TRUE) |>
    dplyr::select(
      dplyr::any_of(c("package", "version",
                      "date", "source"))
    )

  return(r_package_table)

}

get_r_package_info() |>
  reactable::reactable(
    defaultPageSize = 5,
    paginationType = "jump",
  )

```

```{r}
#| label: R Session Info
#| title: "💻 R Session Info"

get_quarto_version <- function(
    test_sys_path = FALSE,
    test_no_path = FALSE
) {

  # Taken from https://github.com/r-lib/sessioninfo/issues/75
  if (isNamespaceLoaded("quarto") && isFALSE(test_sys_path)) {
    path <- quarto::quarto_path() |>
      fs::path_real()
    ver <- system("quarto -V", intern = TRUE)
    if (is.null(path) || isTRUE(test_no_path)) {
      "NA (via quarto)"
    } else {
      paste0(ver, " @ ", path, "/ (via quarto)")
    }
  } else {
    path <- Sys.which("quarto") |>
      fs::path_real()
    if (path == "" || isTRUE(test_no_path)) {
      "NA"
    } else {
      ver <- system("quarto -V", intern = TRUE)
      paste0(ver, " @ ", path)
    }
  }
}


get_knitr_version <- function() {

  knitr_info <- "NA"

  r_package_table <- sessioninfo::package_info(
    pkgs = c("installed")
  ) |>
    dplyr::filter(.data[["package"]] == "knitr")

  if (nrow(r_package_table) == 1) {

    knitr_version <- r_package_table$loadedversion[1]
    knitr_source <- r_package_table$source[1]

    knitr_info <- paste0(
      knitr_version, " from ",
      knitr_source)
  }

  return(knitr_info)

}

get_r_platform_info <- function() {

  r_platform_table <- sessioninfo::platform_info()
  r_platform_table[["quarto"]] <- get_quarto_version()[1]
  r_platform_table[["knitr"]] <- get_knitr_version()[1]

  r_platform_table <- data.frame(
    setting = names(r_platform_table),
    value = unlist(r_platform_table,
                   use.names = FALSE),
    stringsAsFactors = FALSE
  )

  return(r_platform_table)
}

r_platform_table <- get_r_platform_info()

r_platform_table |>
  reactable::reactable(
    defaultPageSize = 5,
    paginationType = "jump",
  )


```

