forked from business-science/free_r_tips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shiny_app.R
78 lines (63 loc) · 1.77 KB
/
shiny_app.R
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
66
67
68
69
70
71
72
73
74
75
76
77
78
# R TIPS ----
# TIP 028 | Esquisse ggplot Builder ---
#
# 👉 For Weekly R-Tips, Sign Up Here: https://learn.business-science.io/r-tips-newsletter
# Why Shiny?
# - Example of Nostradamus (My Forecasting App built with modeltime)
# https://business-science.shinyapps.io/nostradamus/
# LIBRARIES ----
library(esquisse)
library(modeldata)
library(shiny)
data("drinks")
data("mpg")
ui <- fluidPage(
titlePanel("Use esquisse as a Shiny module"),
sidebarLayout(
sidebarPanel(
radioButtons(
inputId = "data",
label = "Data to use:",
choices = c("drinks", "mpg"),
inline = TRUE
)
),
mainPanel(
tabsetPanel(
tabPanel(
title = "esquisse",
esquisserUI(
id = "esquisse",
header = FALSE, # dont display gadget title
choose_data = FALSE # dont display button to change data
)
),
tabPanel(
title = "output",
verbatimTextOutput("module_out")
)
)
)
)
)
server <- function(input, output, session) {
data_r <- reactiveValues(data = drinks, name = "drinks")
observeEvent(input$data, {
if (input$data == "drinks") {
data_r$data <- drinks
data_r$name <- "drinks"
} else {
data_r$data <- mpg
data_r$name <- "mpg"
}
})
result <- callModule(
module = esquisserServer,
id = "esquisse",
data = data_r
)
output$module_out <- renderPrint({
str(reactiveValuesToList(result))
})
}
shinyApp(ui, server)