---
title: "Gestão de Pessoas (Executivo Federal)"
output:
flexdashboard::flex_dashboard:
storyboard: true
orientation: columns
source_code: embed
vertical_layout: fill
theme: paper
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(htmltools)
library(reactable)
library(echarts4r)
```
<!-- Column {data-width=500, data-height=400} -->
<!-- ----------------------------------------------------------------------- -->
<!-- ### Chart A ### [dados.gov/](https://dados.gov.br/dados/conjuntos-dados/gesto-de-pessoas-executivo-federal---cargos-vagos-e-vacncias) -->
<!-- ```{r} -->
<!-- tabela <- readr::read_csv2("tabela.csv") -->
<!-- tabela |> -->
<!-- DT::datatable( -->
<!-- filter = "top", # allows filtering on each column -->
<!-- extensions = c( -->
<!-- "Buttons", # add download buttons, etc -->
<!-- "Scroller" # for scrolling down the rows rather than pagination -->
<!-- ), -->
<!-- rownames = TRUE, # remove rownames -->
<!-- style = "bootstrap", -->
<!-- class = "compact", -->
<!-- width = "50%", -->
<!-- options = list( -->
<!-- dom = "Blrtip", # specify content (search box, etc) -->
<!-- deferRender = TRUE, -->
<!-- pageLength = 30, -->
<!-- scrollY = 300, -->
<!-- scroller = TRUE, -->
<!-- columnDefs = list( -->
<!-- list( -->
<!-- visible = FALSE -->
<!-- , -->
<!-- targets = c(2:3,7) -->
<!-- ) -->
<!-- ), -->
<!-- buttons = list( -->
<!-- I("colvis"), # turn columns on and off -->
<!-- "csv", # download as .csv -->
<!-- "excel" # download as .xlsx -->
<!-- ) -->
<!-- ) -->
<!-- # , -->
<!-- # colnames = c( -->
<!-- # "Data de acesso" = "data", -->
<!-- # "IP de acesso" = "ip", -->
<!-- # "SIAPE" = "siape", -->
<!-- # "Servidor" = "nome.x", -->
<!-- # "Base" = "acesso", -->
<!-- # "Núcleo" = "exercicio", -->
<!-- # "Ano" = "Ano" -->
<!-- # ) -->
<!-- ) -->
<!-- ``` -->
### Cargos Vagos e Vacâncias
<!-- ```{r} -->
<!-- library(htmltools) -->
<!-- library(reactable) -->
<!-- tabela <- readr::read_csv2("tabela.csv") -->
<!-- tab <- tabela |> dplyr::filter( -->
<!-- ANO_MES > lubridate::as_datetime("2022-11-01 00:00:00")) |> -->
<!-- dplyr::select( -->
<!-- NOME_ORGAO, -->
<!-- NOME_CARGO, -->
<!-- Vacancia -->
<!-- ) -->
<!-- # Render a bar chart with a label on the left -->
<!-- bar_chart <- function(label, width = "100%", height = "0.875rem", fill = "#00bfc4", background = NULL) { -->
<!-- bar <- div(style = list(background = fill, width = width, height = height)) -->
<!-- chart <- div(style = list(flexGrow = 1, marginLeft = "0.375rem", background = background), bar) -->
<!-- div(style = list(display = "flex", alignItems = "center"), label, chart) -->
<!-- } -->
<!-- reactable( -->
<!-- tab, -->
<!-- filterable = TRUE, -->
<!-- defaultSorted = "Vacancia", -->
<!-- compact = TRUE, -->
<!-- columns = list( -->
<!-- NOME_ORGAO = colDef( -->
<!-- name = "Órgão" -->
<!-- #format = colFormat(prefix = "@") -->
<!-- ), -->
<!-- NOME_CARGO = colDef( -->
<!-- name = "Cargo", -->
<!-- defaultSortOrder = "desc", -->
<!-- # Render the bar charts using a custom cell render function -->
<!-- # cell = function(value) { -->
<!-- # width <- paste0(value * 100 / max(data$followers), "%") -->
<!-- # # Add thousands separators -->
<!-- # value <- format(value, big.mark = ",") -->
<!-- # bar_chart(value, width = width, fill = "#3fc1c9") -->
<!-- # }, -->
<!-- # And left-align the columns -->
<!-- #align = "left" -->
<!-- ), -->
<!-- Vacancia = colDef( -->
<!-- name = "Vacância", -->
<!-- defaultSortOrder = "desc", -->
<!-- # Render the bar charts using a custom cell render function -->
<!-- cell = function(value) { -->
<!-- width <- paste0(value * 100 / max(tab$Vacancia), "%") -->
<!-- # Add thousands separators -->
<!-- value <- format(value, big.mark = ".") -->
<!-- bar_chart(value, width = width, fill = "#3fc1c9") -->
<!-- }, -->
<!-- # And left-align the columns -->
<!-- align = "left" -->
<!-- ) -->
<!-- ) -->
<!-- ) -->
<!-- ``` -->
```{r}
library(readr)
cargos_vacancia <- read_delim("../cargos_vacancia.csv",
delim = ";", escape_double = FALSE, col_types = cols(ANO_MES = col_datetime(format = "%Y%m"),
CARGO = col_character()), trim_ws = TRUE)
# dados <- cargos_vacancia |>
# rowwise() |>
# mutate(
# Vacancia = sum(c_across(starts_with("VACANCIA_POR_")))
# )
dados <- readr::read_csv2("../data-raw/dados.csv")
tab <- dados |> dplyr::filter(
ANO_MES > lubridate::as_datetime("2022-11-01 00:00:00")) |>
dplyr::select(
NOME_ORGAO,
PLANO_CARREIRA,
NOME_CARGO,
Vacancia
)
# Render a bar chart with a label on the left
bar_chart <- function(label, width = "100%", height = "0.875rem", fill = "#00bfc4", background = NULL) {
bar <- div(style = list(background = fill, width = width, height = height))
chart <- div(style = list(flexGrow = 1, marginLeft = "0.375rem", background = background), bar)
div(style = list(display = "flex", alignItems = "center"), label, chart)
}
reactable(
tab,
filterable = TRUE,
defaultSorted = "Vacancia",
compact = TRUE,
groupBy = c("NOME_ORGAO", "PLANO_CARREIRA"),
columns = list(
NOME_ORGAO = colDef(
name = "Órgão",
aggregate = "unique"),
PLANO_CARREIRA = colDef(
name = "Plano de Carreira"),
NOME_CARGO = colDef(
name = "Cargo"),
Vacancia = colDef(
name = "Vacância",
defaultSortOrder = "desc",
aggregate = "sum",
cell = function(value) {
width <- paste0(value * 100 / max(tab$Vacancia), "%")
# Add thousands separators
value <- format(value, big.mark = ".")
bar_chart(value, width = width, fill = "#3fc1c9")
},
# And left-align the columns
align = "left",
format = colFormat(separators = TRUE)
)
),
bordered = TRUE
)
```
### Cargos Extintos - Top 10
```{r}
dados <- cargos_vacancia |>
select(ANO_MES, NOME_ORGAO, PLANO_CARREIRA, NOME_CARGO, CARGO_EM_EXTINCAO, OCUPADA) |>
dplyr::filter(
ANO_MES > lubridate::as_datetime("2022-11-01 00:00:00"),
CARGO_EM_EXTINCAO == "S"
) |> arrange(desc(OCUPADA)) |> slice(1:10)
dados |>
echarts4r::e_charts(NOME_CARGO) |>
echarts4r::e_bar(serie = OCUPADA) |>
e_x_axis(axisLabel = list(interval = 0, rotate = 45)) |>
echarts4r::e_tooltip(trigger = "axis") # tooltip
```
### Cargos extinto - Dados gerais
```{r}
library(reactable)
library(htmltools)
tab <- cargos_vacancia |>
dplyr::filter(
ANO_MES > lubridate::as_datetime("2022-11-01 00:00:00"),
CARGO_EM_EXTINCAO == "S"
) |>
select(NOME_ORGAO, PLANO_CARREIRA, NOME_CARGO, CARGO_EM_EXTINCAO, OCUPADA) |>
arrange(desc(OCUPADA))
reactable(
tab,
filterable = TRUE,
defaultSorted = "OCUPADA",
compact = TRUE,
columns = list(
NOME_ORGAO = colDef(
name = "Órgão"
#format = colFormat(prefix = "@")
),
NOME_CARGO = colDef(
name = "Cargo",
defaultSortOrder = "desc",
# Render the bar charts using a custom cell render function
# cell = function(value) {
# width <- paste0(value * 100 / max(data$followers), "%")
# # Add thousands separators
# value <- format(value, big.mark = ",")
# bar_chart(value, width = width, fill = "#3fc1c9")
# },
# And left-align the columns
#align = "left"
),
PLANO_CARREIRA = colDef(
name = "Plano de Carreira",
defaultSortOrder = "desc"),
CARGO_EM_EXTINCAO = colDef(
name = "Cargo em extinção",
defaultSortOrder = "desc"),
OCUPADA = colDef(
name = "Ocupada",
defaultSortOrder = "desc",
# Render the bar charts using a custom cell render function
cell = function(value) {
width <- paste0(value * 100 / max(tab$Vacancia), "%")
# Add thousands separators
value <- format(value, big.mark = ".")
bar_chart(value, width = width, fill = "#3fc1c9")
},
# And left-align the columns
align = "left"
)
)
)
```
### Vacâncias em Dezembro de 2022
```{r}
dados <- readr::read_csv2("../data-raw/dados.csv")
tab <- dados |> dplyr::filter(
CARGO_EM_EXTINCAO == "N",
ANO_MES > lubridate::as_datetime("2022-11-01 00:00:00")) |>
dplyr::select(
NOME_ORGAO,
PLANO_CARREIRA,
name = NOME_CARGO,
value=Vacancia
)
# plano de carreira
pl_carreira <- tab |>
dplyr::group_by(NOME_ORGAO, PLANO_CARREIRA) |>
dplyr::summarise(
value = sum(value)
) |> ungroup()
carreira <- tab |> tidyr::nest(children = c(name, value))
Plano_carreira <- carreira |>
left_join(pl_carreira) |>
relocate(NOME_ORGAO,name = PLANO_CARREIRA, value, children) |>
nest(children = c(name, value, children))
Orgao <- tab |>
dplyr::group_by(NOME_ORGAO) |>
dplyr::summarise(
value = sum(value)
)
Plano_Orgao <- Orgao |> left_join(Plano_carreira) |> rename(name= NOME_ORGAO)
e_common(font_family = "helvetica", theme = "westeros")
formatar_numero_br <- function(serie) {
htmlwidgets::JS(
glue::glue(
"function(params) {return Intl.NumberFormat('pt-BR', { style: 'decimal'}).format(params.value[{{serie}}]);}",
.open = "{{",
.close = "}}"
)
)
}
Plano_Orgao |>
e_charts() |>
e_treemap() |>
echarts4r::e_title(text = "Vacância - Dez/2022") |>
echarts4r::e_tooltip("item")
```