Skip to content

Instantly share code, notes, and snippets.

@fernandobarbalho
Created March 20, 2024 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandobarbalho/be92c2fc3744a7a9dc9ee16bc001253b to your computer and use it in GitHub Desktop.
Save fernandobarbalho/be92c2fc3744a7a9dc9ee16bc001253b to your computer and use it in GitHub Desktop.
Dashboard de contas nacionais
---
title: "Contas Nacionais"
output:
flexdashboard::flex_dashboard:
theme:
bg: "#101010"
fg: "#ffda00"
primary: "#183eff"
base_font:
google: Prompt
code_font:
google: JetBrains Mono
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(sidrar)
library(tidyverse)
library(plotly)
library(lubridate)
library(shiny)
library(purrr)
# Install thematic and un-comment for themed static plots (i.e., ggplot2)
thematic::thematic_rmd(bg= "#101010", fg="#ffda00", accent = NA )
gera_trimestres<- function(ano){
ano<-ano
purrr::map_chr(1:4, function(trimestre){
stringr::str_c(ano,"0", trimestre)
})
}
gera_meses_trimestre<- function(trimestre_codigo){
as.Date(paste0(
str_sub(trimestre_codigo,1,4),
"-",
(as.numeric(str_sub(trimestre_codigo,5,6)))*3,
"-01"))
}
#gera_meses_trimestre("201603")
calculate_next_month <- function(input_date) {
input_date <- as.Date(input_date) # Convert input to Date object
next_month <- input_date %m+% months(1) # Add 1 month to the input date
return(next_month)
}
# Função para otimizar a criação de tabelas e cálculo de valor_referencia
calcular_valor_referencia <- function(tabela_base, setor, ano_referencia, direcao) {
if (direcao=="anterior"){
tabela_filtrada <-
tabela_base %>%
filter(setores_e_subsetores == setor,
ano <= ano_referencia) %>%
arrange(desc(ano))
} else{
tabela_filtrada <-
tabela_base %>%
filter(setores_e_subsetores == setor,
ano >= ano_referencia) %>%
arrange(ano)
}
if(nrow(tabela_filtrada) > 1) {
tabela_filtrada$valor_referencia <- NA
tabela_filtrada$valor_referencia[1] <- tabela_filtrada$valor[1]
ajuste <- if_else(direcao == "anterior", -1, 1)
for(i in 2:nrow(tabela_filtrada)){
if (ajuste==-1){
tabela_filtrada$valor_referencia[i] <- tabela_filtrada$valor_referencia[i-1] * (1 + ajuste * (tabela_filtrada$variacao[i-1]/100))
} else{
tabela_filtrada$valor_referencia[i] <- tabela_filtrada$valor_referencia[i-1] * (1 + ajuste * (tabela_filtrada$variacao[i]/100))
}
}
}
return(tabela_filtrada)
}
calcula_serie_constante<- function(tabela_taxa, tabela_precos, trimestres_filtro, conta, ano_referencia){
# Preparação dos dados
dados_grafico_acumulado_lab <- tabela_taxa %>%
filter(setores_e_subsetores %in% conta, variavel_codigo == "6563", trimestre_codigo %in% trimestres_filtro) %>%
mutate(data_nominal = gera_meses_trimestre(trimestre_codigo), setores_e_subsetores = str_wrap(setores_e_subsetores, 20), ano = year(data_nominal)) %>%
select(ano, setores_e_subsetores, valor) %>%
rename(variacao = valor)
tabela_base <- tabela_precos %>%
filter(setores_e_subsetores %in% conta) %>%
mutate(data_nominal = gera_meses_trimestre(trimestre_codigo), setores_e_subsetores = str_wrap(setores_e_subsetores, 20), ano = as.numeric(format(data_nominal, "%Y"))) %>%
summarise(valor = sum(valor), .by = c(setores_e_subsetores, ano)) %>%
ungroup() %>%
inner_join(dados_grafico_acumulado_lab, by = c("ano", "setores_e_subsetores"))
dados_grafico_constante_ano <- unique(tabela_base$setores_e_subsetores) %>%
map_dfr(function(setor) {
tabela_anterior <- calcular_valor_referencia(tabela_base, setor, ano_referencia, "anterior")
tabela_posterior <- calcular_valor_referencia(tabela_base, setor, ano_referencia, "posterior")
bind_rows(tabela_anterior, tabela_posterior[-1, ]) %>%
arrange(ano) %>%
mutate(valor_constante = valor_referencia/10^3)})
}
get_setores_sem_pib<- function(){
(cnt_vt_precos_correntes %>%
filter(setores_e_subsetores!="PIB a preços de mercado") %>%
distinct(setores_e_subsetores))$setores_e_subsetores
}
ano_atual <- as.numeric(format(Sys.Date(), "%Y"))
lista_trimestres<- unlist(lapply(1996:ano_atual, gera_trimestres))
cnt_vt_precos_correntes<-
get_sidra(x = 1846,
period = lista_trimestres)
cnt_vt_precos_correntes <- janitor::clean_names(cnt_vt_precos_correntes)
cnt_taxa_variacao<-
get_sidra(x = 5932,
period = lista_trimestres
)
cnt_taxa_variacao<- janitor::clean_names(cnt_taxa_variacao)
datas_disponiveis<- sort(gera_meses_trimestre(unique(cnt_vt_precos_correntes$trimestre_codigo)), decreasing = TRUE)
data_estatistica<- gera_meses_trimestre(unique(cnt_vt_precos_correntes$trimestre_codigo))
ultima_data<- data_estatistica[NROW(data_estatistica)]
ultimo_mes<- paste0(str_sub(ultima_data,6,7),"/",str_sub(ultima_data,1,4))
ultimo_ano<- year(ultima_data)
```
Dados anuais
=====================================
Inputs {.sidebar data-width=150}
-------------------------------------
```{r}
selectInput(inputId = "conta_ano", label= "Selecione uma ou mais contas", choices= unique(cnt_vt_precos_correntes$setores_e_subsetores),selected = "PIB a preços de mercado", multiple = TRUE, selectize = TRUE )
selectInput(inputId = "ano", label= "Selecione um ou mais anos para destaque", choices= year(datas_disponiveis),selected = year(datas_disponiveis)[1], multiple = TRUE, selectize = TRUE )
# Create placeholder for the downloadButton
uiOutput("downloadUI_conta_anual")
# Create the actual downloadButton
output$downloadUI_conta_anual <- renderUI( {
downloadButton("download_conta_anual","Download", style = "width:100%;")
})
output$download_conta_anual<- downloadHandler(
filename = function() {
paste('dados_grafico_constante_anual', '.csv', sep='')
},
content = function(file) {
#dados_conta_trimestre_corrente <- graph_mapa_regic$data
write.table(dados_grafico_constante_ano, file, sep = ";",row.names = FALSE,fileEncoding = "UTF-8",dec=",")
}
)
tags$br()
# Create placeholder for the downloadButton
uiOutput("downloadUI_conta_perc_ano")
# Create the actual downloadButton
output$downloadUI_conta_perc_ano <- renderUI( {
downloadButton("download_conta_perc_ano","Download", style = "width:100%;")
})
output$download_conta_perc_ano<- downloadHandler(
filename = function() {
paste('dados_grafico_perc_ano', '.csv', sep='')
},
content = function(file) {
#dados_conta_trimestre_corrente <- graph_mapa_regic$data
write.table(dados_grafico_corrente_ano, file, sep = ";",row.names = FALSE,fileEncoding = "UTF-8",dec=",")
}
)
tags$br()
# Create placeholder for the downloadButton
uiOutput("downloadUI_conta_perc_ano_constante")
# Create the actual downloadButton
output$downloadUI_conta_perc_ano_constante <- renderUI( {
downloadButton("download_conta_perc_ano_constante","Download", style = "width:100%;")
})
output$download_conta_perc_ano_constante<- downloadHandler(
filename = function() {
paste('dados_grafico_perc_ano_constante', '.csv', sep='')
},
content = function(file) {
#dados_conta_trimestre_corrente <- graph_mapa_regic$data
write.table(dados_grafico_perc_constante_ano, file, sep = ";",row.names = FALSE,fileEncoding = "UTF-8",dec=",")
}
)
```
Column
-----------------------------------------------------------------------
### Evolução anual - Valores constantes
```{r}
renderPlotly({
contas_sel<- input$conta_ano
ano_referencia<- 2010
trimestres_filtro<- c(lista_trimestres[which(substr(lista_trimestres,5,6)=="04")],
lista_trimestres[length(lista_trimestres)])
dados_grafico_constante_ano<<-
calcula_serie_constante(cnt_taxa_variacao, cnt_vt_precos_correntes, trimestres_filtro, contas_sel, ano_referencia )
sel_data<-
dados_grafico_constante_ano %>%
filter(ano %in% input$ano)
# Criação do gráfico com Plotly
p <- plot_ly(data = dados_grafico_constante_ano,
x = ~ano,
y = ~valor_constante,
type = 'scatter',
mode = 'lines',
color = ~setores_e_subsetores,
colors = 'Accent',
text = ~paste0(format(ano), ": ", round(valor_constante,1)),
hoverinfo = 'text') %>%
add_trace(data = sel_data,
type = 'scatter',
mode = 'text+markers',
text = ~str_wrap(paste0(ano, ": ", round(valor_constante,1)), 100),
textposition = 'top left',
textfont = list(color = 'white', size = 10),
showlegend = FALSE) %>%
layout(title = list(text = 'Evolução anual: valores constantes para 2010',
font = list(color = '#FFFFFF')),
yaxis = list(title = 'Valores em R$ bi',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
xaxis = list(title = '',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
plot_bgcolor = '#1c1b1b',
paper_bgcolor = '#101010',
showlegend = TRUE,
legend = list(font = list(color = '#FFFFFF')))
# Exibição do gráfico
p
})
```
Column
-----------------------------------------------------------------------
### Evolução Anual - (%)Valor adicionado - valores Correntes
```{r}
renderPlotly ({
dados_pib<-
cnt_vt_precos_correntes %>%
filter(setores_e_subsetores_codigo == "90705")%>%
select(trimestre_codigo, valor) %>%
rename(valor_pib = valor)
# Preparação dos dados
dados_grafico_corrente_ano <<- cnt_vt_precos_correntes %>%
filter(setores_e_subsetores %in% input$conta_ano) %>%
inner_join(dados_pib) %>%
mutate(data_nominal = gera_meses_trimestre(trimestre_codigo), # Essa função precisa ser definida ou alterada conforme o contexto
setores_e_subsetores = str_wrap(setores_e_subsetores,20)) %>%
group_by(ano = format(data_nominal, "%Y"),
setores_e_subsetores) %>%
summarize(data_nominal = min(data_nominal),
valor = sum(valor),
valor_pib = sum(valor_pib)) %>%
ungroup() %>%
mutate(valor_perc = ((valor/valor_pib))*100)
# str_wrap pode precisar ser ajustado
sel_data <- dados_grafico_corrente_ano %>%
filter(year(data_nominal) %in% input$ano)
# Criação do gráfico com Plotly
p <- plot_ly(data = dados_grafico_corrente_ano,
x = ~data_nominal,
y = ~valor_perc,
type = 'scatter',
mode = 'lines',
color = ~setores_e_subsetores,
colors = 'Accent',
text = ~paste0(format(data_nominal,"%Y"), ": ", round(valor_perc,1),"%"),
hoverinfo = 'text') %>%
add_trace(data = sel_data,
type = 'scatter',
mode = 'text+markers',
text = ~str_wrap(paste0(format(data_nominal,"%Y"), ": ", round(valor_perc,1),"%"), 100),
textposition = 'top left',
textfont = list(color = 'white', size = 10),
showlegend = FALSE) %>%
layout(title = list(text = 'Evolução anual: (%)Valor adicionado - valores Correntes',
font = list(color = '#FFFFFF')),
yaxis = list(title = 'Valores em %',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
xaxis = list(title = '',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
plot_bgcolor = '#1c1b1b',
paper_bgcolor = '#101010',
showlegend = TRUE,
legend = list(font = list(color = '#FFFFFF')))
# Exibição do gráfico
p
})
```
### Evolução Anual - (%)Valor adicionado - constantes
```{r}
renderPlotly ({
contas_sel<- input$conta_ano
ano_referencia<- 2010
trimestres_filtro<- c(lista_trimestres[which(substr(lista_trimestres,5,6)=="04")],
lista_trimestres[length(lista_trimestres)])
dados_pib<-calcula_serie_constante(cnt_taxa_variacao, cnt_vt_precos_correntes, trimestres_filtro, "Valor adicionado a preços básicos", ano_referencia )
dados_pib <-
dados_pib %>%
select(ano, valor_constante) %>%
rename(valor_pib = valor_constante)
dados_series<-
calcula_serie_constante(cnt_taxa_variacao, cnt_vt_precos_correntes, trimestres_filtro, contas_sel, ano_referencia )
# Preparação dos dados
dados_grafico_perc_constante_ano <<-
dados_series %>%
inner_join(dados_pib) %>%
mutate(valor_perc = ((valor_constante/valor_pib))*100)
# str_wrap pode precisar ser ajustado
sel_data <- dados_grafico_perc_constante_ano %>%
filter(ano %in% input$ano)
# Criação do gráfico com Plotly
p <- plot_ly(data = dados_grafico_perc_constante_ano,
x = ~ano,
y = ~valor_perc,
type = 'scatter',
mode = 'lines',
color = ~setores_e_subsetores,
colors = 'Accent',
text = ~paste0(ano, ": ", round(valor_perc,1),"%"),
hoverinfo = 'text') %>%
add_trace(data = sel_data,
type = 'scatter',
mode = 'text+markers',
text = ~str_wrap(paste0(ano, ": ", round(valor_perc,1),"%"), 100),
textposition = 'top left',
textfont = list(color = 'white', size = 10),
showlegend = FALSE) %>%
layout(title = list(text = 'Evolução anual: (%)valor adicionado - valores constantes para 2010',
font = list(color = '#FFFFFF')),
yaxis = list(title = 'Valores em %',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
xaxis = list(title = '',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
plot_bgcolor = '#1c1b1b',
paper_bgcolor = '#101010',
showlegend = TRUE,
legend = list(font = list(color = '#FFFFFF')))
# Exibição do gráfico
p
})
```
Variações
=====================================
Inputs {.sidebar data-width=150}
-------------------------------------
```{r}
selectInput(inputId = "conta_var", label= "Selecione uma ou mais contas", choices= unique(cnt_vt_precos_correntes$setores_e_subsetores),selected = "PIB a preços de mercado", multiple = TRUE, selectize = TRUE )
selectInput(inputId = "trimestre_var", label= "Selecione um ou mais trimestre para destaque", choices= datas_disponiveis,selected = datas_disponiveis[1], multiple = TRUE, selectize = TRUE )
selectInput(inputId = "ano_var", label= "Selecione um ou mais anos para destaque", choices= year(datas_disponiveis),selected = year(datas_disponiveis)[1], multiple = TRUE, selectize = TRUE )
# Create placeholder for the downloadButton
uiOutput("downloadUI_conta_var_trim_anual")
# Create the actual downloadButton
output$downloadUI_conta_var_trim_anual <- renderUI( {
downloadButton("download_conta_var_trim_anual","Download", style = "width:100%;")
})
output$download_conta_var_trim_anual<- downloadHandler(
filename = function() {
paste('dados_grafico_var_trim_anual', '.csv', sep='')
},
content = function(file) {
#dados_conta_trimestre_corrente <- graph_mapa_regic$data
write.table(dados_grafico_taxa_trim_ano_anterior, file, sep = ";",row.names = FALSE,fileEncoding = "UTF-8",dec=",")
}
)
tags$br()
# Create placeholder for the downloadButton
uiOutput("downloadUI_conta_var_trim_trim")
# Create the actual downloadButton
output$downloadUI_conta_var_trim_trim <- renderUI( {
downloadButton("download_conta_var_trim_trim","Download", style = "width:100%;")
})
output$download_conta_var_trim_trim<- downloadHandler(
filename = function() {
paste('dados_grafico_var_trim_trim', '.csv', sep='')
},
content = function(file) {
#dados_conta_trimestre_corrente <- graph_mapa_regic$data
write.table(dados_grafico_taxa_trim_anterior, file, sep = ";",row.names = FALSE,fileEncoding = "UTF-8",dec=",")
}
)
tags$br()
# Create placeholder for the downloadButton
uiOutput("downloadUI_conta_var_ano")
# Create the actual downloadButton
output$downloadUI_conta_var_ano <- renderUI( {
downloadButton("download_conta_var_ano","Download", style = "width:100%;")
})
output$download_conta_var_ano<- downloadHandler(
filename = function() {
paste('dados_grafico_conta_var_ano', '.csv', sep='')
},
content = function(file) {
#dados_conta_trimestre_corrente <- graph_mapa_regic$data
write.table(dados_grafico_acumulado_ano, file, sep = ";",row.names = FALSE,fileEncoding = "UTF-8",dec=",")
}
)
tags$br()
# Create placeholder for the downloadButton
uiOutput("downloadUI_conta_var_acumulado")
# Create the actual downloadButton
output$downloadUI_conta_var_acumulado <- renderUI( {
downloadButton("download_conta_var_acumulado","Download", style = "width:100%;")
})
output$download_conta_var_acumulado<- downloadHandler(
filename = function() {
paste('dados_grafico_conta_var_acumulado', '.csv', sep='')
},
content = function(file) {
#dados_conta_trimestre_corrente <- graph_mapa_regic$data
write.table(dados_grafico_taxa_acum_ano, file, sep = ";",row.names = FALSE,fileEncoding = "UTF-8",dec=",")
}
)
```
Variações
-----------------------------------------------------------------------
### Variação trimestral (em relação ao mesmo período do ano anterior)
```{r}
renderPlotly({
dados_grafico_taxa_trim_ano_anterior<<-
cnt_taxa_variacao %>%
filter(setores_e_subsetores %in% input$conta_var,
variavel_codigo == "6561") %>%
mutate(data_nominal = gera_meses_trimestre(trimestre_codigo),
setores_e_subsetores = str_wrap(setores_e_subsetores,20))
sel_data<-
dados_grafico_taxa_trim_ano_anterior %>%
filter(data_nominal %in% input$trimestre_var)
# Criação do gráfico com Plotly
p <- plot_ly(data = dados_grafico_taxa_trim_ano_anterior,
x = ~data_nominal,
y = ~valor,
type = 'scatter',
mode = 'lines',
color = ~setores_e_subsetores,
colors = 'Accent',
text = ~paste0(format(data_nominal,"%m/%y"), ": ", round(valor,1),"%"),
hoverinfo = 'text') %>%
add_trace(data = sel_data,
type = 'scatter',
mode = 'text+markers',
text = ~str_wrap(paste0(format(data_nominal,"%m/%y"), ": ", round(valor,1),"%"), 100),
textposition = 'top left',
textfont = list(color = 'white', size = 10),
showlegend = FALSE) %>%
layout(title = list(text = 'Taxa trimestral ano contra ano',
font = list(color = '#FFFFFF')),
yaxis = list(title = 'Valores em (%)',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
xaxis = list(title = '',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
plot_bgcolor = '#1c1b1b',
paper_bgcolor = '#101010',
showlegend = TRUE,
legend = list(font = list(color = '#FFFFFF')))
# Exibição do gráfico
p
})
```
### Variação trimestral (trimestre contra trimestre)
```{r}
renderPlotly({
dados_grafico_taxa_trim_anterior<<-
cnt_taxa_variacao %>%
filter(setores_e_subsetores %in% input$conta_var,
variavel_codigo == "6564") %>%
mutate(data_nominal = gera_meses_trimestre(trimestre_codigo),
setores_e_subsetores = str_wrap(setores_e_subsetores,20))
sel_data<-
dados_grafico_taxa_trim_anterior %>%
filter(data_nominal %in% input$trimestre_var)
# Criação do gráfico com Plotly
p <- plot_ly(data = dados_grafico_taxa_trim_anterior,
x = ~data_nominal,
y = ~valor,
type = 'scatter',
mode = 'lines',
color = ~setores_e_subsetores,
colors = 'Accent',
text = ~paste0(format(data_nominal,"%m/%y"), ": ", round(valor,1),"%"),
hoverinfo = 'text') %>%
add_trace(data = sel_data,
type = 'scatter',
mode = 'text+markers',
text = ~str_wrap(paste0(format(data_nominal,"%m/%y"), ": ", round(valor,1),"%"), 100),
textposition = 'top left',
textfont = list(color = 'white', size = 10),
showlegend = FALSE) %>%
layout(title = list(text = 'Taxa trimestre contra trimestre',
font = list(color = '#FFFFFF')),
yaxis = list(title = 'Valores em (%)',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
xaxis = list(title = '',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
plot_bgcolor = '#1c1b1b',
paper_bgcolor = '#101010',
showlegend = TRUE,
legend = list(font = list(color = '#FFFFFF')))
# Exibição do gráfico
p
})
```
Column
-----------------------------------------------------------------------
### Taxa acumulada ao longo do ano
```{r}
renderPlotly({
trimestres_filtro<- c(lista_trimestres[which(substr(lista_trimestres,5,6)=="04")],
lista_trimestres[length(lista_trimestres)])
dados_grafico_acumulado_ano<<-
cnt_taxa_variacao %>%
filter(setores_e_subsetores %in% input$conta_var,
variavel_codigo == "6563",
trimestre_codigo %in% trimestres_filtro
) %>%
mutate(data_nominal = gera_meses_trimestre(trimestre_codigo),
setores_e_subsetores = str_wrap(setores_e_subsetores,20),
ano = year(data_nominal))
sel_data<-
dados_grafico_acumulado_ano %>%
filter(ano %in% input$ano_var)
# Criação do gráfico com Plotly
p <- plot_ly(data = dados_grafico_acumulado_ano,
x = ~ano,
y = ~valor,
type = 'scatter',
mode = 'lines',
color = ~setores_e_subsetores,
colors = 'Accent',
text = ~paste0(ano, ": ", round(valor,1),"%"),
hoverinfo = 'text') %>%
add_trace(data = sel_data,
type = 'scatter',
mode = 'text+markers',
text = ~str_wrap(paste0(ano, ": ", round(valor,1),"%"), 100),
textposition = 'top left',
textfont = list(color = 'white', size = 10),
showlegend = FALSE) %>%
layout(title = list(text = 'Taxa acumulada ao longo do ano',
font = list(color = '#FFFFFF')),
yaxis = list(title = 'Valores em (%)',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
xaxis = list(title = '',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
plot_bgcolor = '#1c1b1b',
paper_bgcolor = '#101010',
showlegend = TRUE,
legend = list(font = list(color = '#FFFFFF')))
# Exibição do gráfico
p
})
```
### Variação acumulada em quatro trimestres
```{r}
renderPlotly({
dados_grafico_taxa_acum_ano<<-
cnt_taxa_variacao %>%
filter(setores_e_subsetores %in% input$conta_var,
variavel_codigo == "6562") %>%
mutate(data_nominal = gera_meses_trimestre(trimestre_codigo),
setores_e_subsetores = str_wrap(setores_e_subsetores,20))
sel_data<-
dados_grafico_taxa_acum_ano %>%
filter(data_nominal %in% input$trimestre_var)
# Criação do gráfico com Plotly
p <- plot_ly(data = dados_grafico_taxa_acum_ano,
x = ~data_nominal,
y = ~valor,
type = 'scatter',
mode = 'lines',
color = ~setores_e_subsetores,
colors = 'Accent',
text = ~paste0(format(data_nominal,"%m/%y"), ": ", round(valor,1),"%"),
hoverinfo = 'text') %>%
layout(title = list(text = 'Taxa acumulada em quatro trimestres',
font = list(color = '#FFFFFF')),
yaxis = list(title = 'Valores em (%)',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
xaxis = list(title = '',
titlefont = list(color = '#FFFFFF'),
tickfont = list(color = '#FFFFFF'),
gridcolor = '#101010'),
plot_bgcolor = '#1c1b1b',
paper_bgcolor = '#101010',
showlegend = TRUE,
legend = list(font = list(color = '#FFFFFF')))%>%
add_trace(data = sel_data,
type = 'scatter',
mode = 'text+markers',
text = ~str_wrap(paste0(format(data_nominal,"%m/%y"), ": ", round(valor,1),"%"), 100),
textposition = 'top left',
textfont = list(color = 'white', size = 10),
showlegend = FALSE)
# Exibição do gráfico
p
})
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment