Skip to content

Commit

Permalink
return to slow app
Browse files Browse the repository at this point in the history
  • Loading branch information
calderonsamuel committed Nov 18, 2024
1 parent 3d4d5f0 commit b1d356a
Showing 1 changed file with 22 additions and 37 deletions.
59 changes: 22 additions & 37 deletions app.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
library(shiny)
library(bslib)
library(tidyverse)
library(future)
library(promises)

plan(multisession)

survey <- arrow::read_parquet("data/survey.parquet")
survey <- read.csv("data/survey.csv") |>
slice_sample(n = 5000, by = region)

ui <- page_sidebar(

Expand All @@ -23,77 +20,65 @@ ui <- page_sidebar(
max = 100,
value = 100,
step = 10
),
input_task_button(
id = "compute",
label = "Calcular"
)
),

useBusyIndicators(),

card(
max_height = "50%",
DT::DTOutput("table")
tableOutput("table")
),

layout_columns(
col_widths = c(4, 4, 4),

card(
plotly::plotlyOutput("histogram")
plotOutput("histogram")
),
card(
full_screen = TRUE,
plotly::plotlyOutput("by_transport")
plotOutput("by_transport")
),
card(
full_screen = TRUE,
plotly::plotlyOutput("by_type")
plotOutput("by_type")
)

)

)

server <- function(input, output, session) {
filter_task <- ExtendedTask$new(function(p_survey, p_region, p_age) {
future_promise({
p_survey |>
dplyr::filter(region == p_region) |>
dplyr::filter(age <= p_age)
})
}) |>
bind_task_button("compute")

observe(filter_task$invoke(survey, input$region, input$age)) |>
bindEvent(input$compute, ignoreNULL = FALSE)

filtered <- reactive({
filter_task$result()
})

output$table <- DT::renderDT({
filtered()
output$table <- renderTable({
survey |>
filter(region == input$region) |>
filter(age <= input$age)
})

output$histogram <- plotly::renderPlotly({
filtered() |>
output$histogram <- renderPlot({
survey |>
filter(region == input$region) |>
filter(age <= input$age) |>
ggplot(aes(temps_trajet_en_heures)) +
geom_histogram(bins = 20) +
theme_light()
})

output$by_transport <- plotly::renderPlotly({
filtered() |>
output$by_transport <- renderPlot({
survey |>
filter(region == input$region) |>
filter(age <= input$age) |>
ggplot(aes(temps_trajet_en_heures)) +
geom_histogram(bins = 20) +
facet_wrap(~transport) +
theme_light()
})

output$by_type <- plotly::renderPlotly({
filtered() |>
output$by_type <- renderPlot({
survey |>
filter(region == input$region) |>
filter(age <= input$age) |>
ggplot(aes(temps_trajet_en_heures)) +
geom_histogram(bins = 20) +
facet_wrap(~type) +
Expand Down

0 comments on commit b1d356a

Please sign in to comment.