---
title: "Customise your static shiny"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{edit_static_content}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

## Introduction

In this vignette we will see how to edit the panelDetails object to have one more level of customisation.

### Load packages

```{r}
library(OmopViewer)
library(dplyr, warn.conflicts = FALSE)
library(omopgenerics, warn.conflicts = FALSE)
```

### Mock data

We will use the incidence results obtained by the package, we can subset our reuslts using the following command:

```{r}
result <- omopViewerResults |> 
  filterSettings(result_type == "incidence")
```

As we can see it contains data from different settings:

```{r}
result |>
  settings() |>
  glimpse()
```

In this case we will create two incidence tabs one for the `Male` data and another one for the `Female` data, the starting point will be the default incidence tab, we can ibtain it using:

```{r}
getPanel("incidence")
```

Or just producing it from the results:

```{r}
panelDetailsFromResult(result = result)
```

We can then define our `panelDetails` object using:

```{r}
panelDetails <- list(
  incidence_female = getPanel("incidence"),
  incidence_male = getPanel("incidence")
)
```

For the moment this the only thing that will create is two panels of incidence, but with the same information, the first thing that we will do is to restrict to the corresponding data in each one of the panels:

```{r}
panelDetails$incidence_female$data <- list(denominator_sex = "Female")
panelDetails$incidence_male$data <- list(denominator_sex = "Male")
```

We can now for example edit the title:
```{r}
panelDetails$incidence_female$title <- "Incidence in Female"
panelDetails$incidence_male$title <- "Incidence in Male"
```

And the icons:
```{r}
panelDetails$incidence_female$icon <- "venus"
panelDetails$incidence_male$icon <- "mars"
```

Let's create the shiny and see how it looks like:

```{r, eval = FALSE}
exportStaticApp(result = result, panelDetails = panelDetails, directory = tempdir())
```

We can for example remove the *tidy* panel for the female tab and the plot panel for the male tab like this:

```{r}
panelDetails$incidence_female$content$tidy <- NULL
panelDetails$incidence_male$content$plot <- NULL
```

Finally we will remove the filter for `denominator_sex` for both panels:

```{r}
panelDetails$incidence_female$exclude_filters <- c(panelDetails$incidence_female$exclude_filters, "denominator_sex")
panelDetails$incidence_male$exclude_filters <- c(panelDetails$incidence_male$exclude_filters, "denominator_sex")
```

We can now regenerate the shiny and see how our changes were effective:

```{r, eval = FALSE}
exportStaticApp(result = result, panelDetails = panelDetails, directory = tempdir())
```
