-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.R
More file actions
65 lines (56 loc) · 1.36 KB
/
module.R
File metadata and controls
65 lines (56 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
plotUI <- function(id) {
ns <- NS(id)
fluidRow(
column(width = 10,
echarts4r::echarts4rOutput(ns("plot")) %>%
shinycssloaders::withSpinner()
),
column(width = 2,
actionButton(
inputId = ns("bar"),
label = "",
icon = icon("chart-bar")
),
actionButton(
inputId = ns("pie"),
label = "",
icon = icon("chart-pie")
)
)
)
}
plotServer <- function(id, df) {
moduleServer(
id,
function(input, output, session) {
# Setting reactiveValues for changing plot types
rv <- reactiveValues(
plot_type = "bar",
plot = NULL
)
# Observer and main calculation
observeEvent(c(df(), rv$plot_type),{
# Timeout to show NO asyncronity
Sys.sleep(5)
if (rv$plot_type == "bar") {
rv$plot <- df() %>%
plot_bar()
} else {
rv$plot <- df() %>%
plot_pie()
}
})
# Observers for actionButtion clicks
observeEvent(input$bar, {
rv$plot_type <- "bar"
})
observeEvent(input$pie,{
rv$plot_type <- "pie"
})
# Render Plots
output$plot <- echarts4r::renderEcharts4r({
req(rv$plot)
})
}
)
}