-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8cdfae
commit ced33c4
Showing
13 changed files
with
74,141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# https://plotly.com/r/ | ||
|
||
library(shiny) | ||
|
||
ui <- fluidPage( | ||
titlePanel("Plotly"), | ||
sidebarLayout( | ||
sidebarPanel( | ||
selectInput( | ||
inputId = "variavel", | ||
label = "Selecione a variável", | ||
choices = c("cyl", "vs", "am", "gear") | ||
), | ||
textOutput("texto_click") | ||
), | ||
mainPanel( | ||
plotly::plotlyOutput("grafico_plotly"), | ||
plotly::plotlyOutput("grafico_ggplotly"), | ||
) | ||
) | ||
) | ||
|
||
server <- function(input, output, session) { | ||
|
||
output$grafico_plotly <- plotly::renderPlotly({ | ||
mtcars |> | ||
dplyr::select(x = dplyr::one_of(input$variavel)) |> | ||
dplyr::count(x) |> | ||
plotly::plot_ly( | ||
x = ~x, | ||
y = ~n, | ||
type = "bar", | ||
source = "grafico_plotly" | ||
) | ||
}) | ||
|
||
output$grafico_ggplotly <- plotly::renderPlotly({ | ||
p <- mtcars |> | ||
dplyr::select(x = dplyr::one_of(input$variavel)) |> | ||
dplyr::count(x) |> | ||
ggplot2::ggplot(ggplot2::aes(x = x, y = n)) + | ||
ggplot2::geom_col() + | ||
ggplot2::theme_minimal() | ||
plotly::ggplotly(p, source = "grafico_ggplotly") | ||
}) | ||
|
||
output$texto_click <- renderText({ | ||
clique <- plotly::event_data("plotly_click", source = "grafico_plotly") | ||
req(clique) | ||
variavel <- isolate(input$variavel) | ||
glue::glue("Existem {clique$y} carros com {variavel} = {clique$x}.") | ||
}) | ||
|
||
} | ||
|
||
shinyApp(ui, server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# https://echarts4r.john-coene.com/ | ||
# https://echarts.apache.org/en/index.html | ||
|
||
library(shiny) | ||
|
||
ui <- fluidPage( | ||
titlePanel("Echarts"), | ||
sidebarLayout( | ||
sidebarPanel( | ||
selectInput( | ||
inputId = "variavel", | ||
label = "Selecione a variável", | ||
choices = c("cyl", "vs", "am", "gear") | ||
), | ||
textOutput("texto_click") | ||
), | ||
mainPanel( | ||
echarts4r::echarts4rOutput("grafico") | ||
) | ||
) | ||
) | ||
|
||
server <- function(input, output, session) { | ||
|
||
output$grafico <- echarts4r::renderEcharts4r({ | ||
mtcars |> | ||
dplyr::select(x = dplyr::one_of(input$variavel)) |> | ||
dplyr::count(x) |> | ||
dplyr::mutate(x = as.character(x)) |> | ||
echarts4r::e_charts(x) |> | ||
echarts4r::e_bar(serie = n) |> | ||
echarts4r::e_legend(show = FALSE) |> | ||
echarts4r::e_x_axis( | ||
name = input$variavel, | ||
nameLocation = "center", | ||
nameGap = 30 | ||
) | ||
}) | ||
|
||
output$texto_click <- renderText({ | ||
clique <- input$grafico_clicked_data | ||
req(clique) | ||
variavel <- isolate(input$variavel) | ||
glue::glue("Existem {clique$value[2]} carros com {variavel} = {clique$value[1]}.") | ||
}) | ||
|
||
} | ||
|
||
shinyApp(ui, server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# https://rstudio.github.io/leaflet | ||
# https://rstudio.github.io/leaflet/articles/shiny.html | ||
|
||
# municipios <- abjData::pnud_min |> | ||
# dplyr::filter(ano == 2010) |> | ||
# dplyr::select(muni_id, uf_sigla, muni_nm, idhm, lat, lon) |> | ||
# dplyr::arrange(uf_sigla, muni_nm) | ||
# | ||
# readr::write_csv(municipios, "curso_gravado/scripts/municipios.csv") | ||
|
||
dados <- readr::read_csv("municipios.csv") | ||
|
||
library(shiny) | ||
|
||
ui <- fluidPage( | ||
titlePanel("Leaflet"), | ||
sidebarLayout( | ||
sidebarPanel( | ||
selectInput( | ||
inputId = "estado", | ||
label = "Selecione o estado", | ||
choices = unique(dados$uf_sigla) | ||
), | ||
selectInput( | ||
inputId = "muni", | ||
label = "Selecione o município", | ||
choices = "", | ||
multiple = TRUE | ||
), | ||
textOutput("texto") | ||
), | ||
mainPanel( | ||
leaflet::leafletOutput("mapa") | ||
) | ||
) | ||
) | ||
|
||
server <- function(input, output, session) { | ||
|
||
observe({ | ||
municipios <- dados |> | ||
dplyr::filter(uf_sigla == input$estado) |> | ||
dplyr::select(muni_nm, muni_id) |> | ||
tibble::deframe() | ||
|
||
updateSelectInput( | ||
session = session, | ||
inputId = "muni", | ||
choices = municipios, | ||
selected = municipios[1] | ||
) | ||
}) | ||
|
||
output$mapa <- leaflet::renderLeaflet({ | ||
dados |> | ||
dplyr::filter(muni_id %in% input$muni) |> | ||
leaflet::leaflet() |> | ||
leaflet::addTiles() |> | ||
leaflet::addMarkers( | ||
lng = ~lon, | ||
lat = ~lat, | ||
layerId = ~muni_id, | ||
popup = ~paste(muni_nm, "<br>", "IDHM: ", idhm) | ||
) | ||
}) | ||
|
||
output$texto <- renderText({ | ||
clique <- input$mapa_marker_click | ||
|
||
req(clique) | ||
|
||
muni <- dados |> | ||
dplyr::filter(muni_id == clique$id) |> | ||
dplyr::pull(muni_nm) | ||
|
||
glue::glue("Você clicou no município {muni}") | ||
|
||
}) | ||
|
||
} | ||
|
||
shinyApp(ui, server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
library(shiny) | ||
|
||
ui <- fluidPage( | ||
titlePanel("Echarts"), | ||
sidebarLayout( | ||
sidebarPanel( | ||
selectInput( | ||
inputId = "variavel", | ||
label = "Selecione a variável", | ||
choices = c("cyl", "vs", "am", "gear") | ||
), | ||
textOutput("texto_click"), | ||
hr(), | ||
auth0::logoutButton() | ||
), | ||
mainPanel( | ||
echarts4r::echarts4rOutput("grafico") | ||
) | ||
) | ||
) | ||
|
||
server <- function(input, output, session) { | ||
output$grafico <- echarts4r::renderEcharts4r({ | ||
mtcars |> | ||
dplyr::select(x = dplyr::one_of(input$variavel)) |> | ||
dplyr::count(x) |> | ||
dplyr::mutate(x = as.character(x)) |> | ||
echarts4r::e_charts(x) |> | ||
echarts4r::e_bar(serie = n) |> | ||
echarts4r::e_legend(show = FALSE) |> | ||
echarts4r::e_x_axis( | ||
name = input$variavel, | ||
nameLocation = "center", | ||
nameGap = 30 | ||
) | ||
}) | ||
|
||
output$texto_click <- renderText({ | ||
clique <- input$grafico_clicked_data | ||
req(clique) | ||
variavel <- isolate(input$variavel) | ||
glue::glue("Existem {clique$value[2]} carros com {variavel} = {clique$value[1]}.") | ||
}) | ||
} | ||
|
||
auth0::shinyAppAuth0(ui, server) | ||
|
||
# auth0::use_auth0() | ||
# usethis::edit_r_environ() | ||
|
||
# options(shiny.port = 8080) | ||
# shiny::runApp("exemplos/auth0/") | ||
|
||
# http://localhost:8080 to the "Allowed Callback URLs", | ||
# "Allowed Web Origins" and "Allowed Logout URLs" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
library(shiny) | ||
|
||
dados <- pokemon::pokemon_ptbr | ||
|
||
ui <- fluidPage( | ||
titlePanel("Gerando relatórios"), | ||
sidebarLayout( | ||
sidebarPanel( | ||
selectInput( | ||
"pokemon", | ||
label = "Selecione um pokemon", | ||
choices = unique(dados$pokemon) | ||
), | ||
actionButton("visualizar", "Visualizar relatório"), | ||
downloadButton("baixar", "Baixar relatório") | ||
), | ||
mainPanel( | ||
uiOutput("preview") | ||
) | ||
) | ||
) | ||
|
||
server <- function(input, output, session) { | ||
|
||
iframe <- eventReactive(input$visualizar, { | ||
withProgress(message = "Gerando relatório...", { | ||
incProgress(0.3) | ||
rmarkdown::render( | ||
input = "relatorio.Rmd", | ||
output_dir = "www", | ||
params = list(pokemon = input$pokemon) | ||
) | ||
incProgress(0.4) | ||
tags$iframe( | ||
src = "relatorio.html", | ||
width = "100%", | ||
height = 600 | ||
) | ||
}) | ||
}) | ||
|
||
output$preview <- renderUI({ | ||
req(iframe()) | ||
iframe() | ||
}) | ||
|
||
output$baixar <- downloadHandler( | ||
filename = function() {glue::glue("relatorio_{input$pokemon}.pdf")}, | ||
content = function(file) { | ||
|
||
arquivo_html <- tempfile(fileext = ".html") | ||
|
||
withProgress(message = "Gerando relatório...", { | ||
|
||
incProgress(0.3) | ||
|
||
rmarkdown::render( | ||
input = "relatorio.Rmd", | ||
output_file = arquivo_html, | ||
params = list(pokemon = input$pokemon) | ||
) | ||
|
||
incProgress(0.4) | ||
|
||
pagedown::chrome_print( | ||
input = arquivo_html, | ||
output = file | ||
) | ||
|
||
}) | ||
|
||
} | ||
) | ||
|
||
} | ||
|
||
shinyApp(ui, server) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi tristique a ante a convallis. Etiam porttitor quam in ante *volutpat pellentesque*. Sed hendrerit ullamcorper quam, sed rutrum felis viverra non. Aliquam eget eleifend quam. Donec nec porttitor enim, sit amet vestibulum augue. Nulla facilisi. Sed rutrum tempor lectus, sed sodales mi. Pellentesque sit amet tristique arcu. Etiam nec laoreet leo. **Sed venenatis sapien vitae magna scelerisque volutpat**. | ||
|
||
Nunc vitae blandit elit, non scelerisque mi. Quisque eget purus sit amet nibh commodo ultrices. Mauris risus erat, posuere vel velit vel, dapibus sodales augue. Etiam aliquet eget justo non gravida. Aenean sapien diam, porttitor a neque a, ultrices dignissim libero. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed blandit nisi quam. Pellentesque gravida ultricies eros ac lacinia. Suspendisse quis lectus semper, vehicula diam id, vehicula odio. Fusce sed massa eget lorem aliquam egestas. | ||
|
||
Integer varius eget nunc at pretium. Sed eu tellus lacinia, ornare dui ac, semper velit. Aenean sollicitudin mi volutpat, consequat lorem sit amet, bibendum metus. Suspendisse potenti. Suspendisse at lacus risus. Sed ut tincidunt enim. Nulla luctus enim non bibendum vehicula. Fusce dolor mi, placerat in risus id, elementum pulvinar dui. Duis eget pretium dolor. Mauris dignissim libero a quam imperdiet venenatis. Praesent ac laoreet tortor, in luctus tortor. Pellentesque varius odio lobortis dapibus accumsan. Integer sed tempus felis, in maximus ante. Quisque eu eros vel dui placerat varius et id est. | ||
|
||
Proin dictum vehicula dignissim. Nunc nec ex turpis. Sed nunc sem, pretium eget euismod non, viverra nec mauris. Nam ante lectus, malesuada non eros sed, lobortis tincidunt neque. In vitae justo velit. Maecenas nec nisi libero. Proin venenatis eu erat vitae tristique. Nulla accumsan dapibus lorem, quis lacinia velit luctus et. Nullam quis justo consectetur, suscipit risus a, laoreet nulla. Mauris risus massa, sodales vitae odio id, tincidunt vestibulum leo. | ||
|
||
Pellentesque tincidunt suscipit mi, non sollicitudin lorem sollicitudin ac. Sed eleifend ligula ac lorem sagittis, vitae efficitur libero tincidunt. Ut quis mi non eros vulputate congue. Cras sit amet metus quis sem congue varius sit amet ut arcu. Vivamus eleifend consequat velit, a sodales diam. In hac habitasse platea dictumst. Proin ultrices, purus ut dignissim tempor, odio lorem scelerisque metus, ac congue libero leo nec arcu. Integer malesuada felis non consequat fermentum. Pellentesque pretium porta tristique. Sed ac ex faucibus odio interdum finibus vitae non tellus. Vivamus molestie sagittis consectetur. |
Binary file not shown.
Oops, something went wrong.