Skip to content

Commit 4c39109

Browse files
committed
shinyapps deployment scripts
1 parent 84c9d91 commit 4c39109

File tree

41 files changed

+883
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+883
-39
lines changed

_redirects

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
https://plotly-book.cpsievert.me/* https://plotly-r.com/:splat 301!
22

3-
# redirect some links from from the 1st edition
3+
# redirect some links from the 1st edition
4+
45
https://plotly-r.com/plot-ly-for-collaboration.html https://plotly-r.com
56

67
https://plotly-r.com/extending-ggplotly.html https://plotly-r.com/improving-ggplotly.html
@@ -16,3 +17,6 @@ https://plotly-r.com/linking-views-without-shiny.html https://plotly-r.com/clien
1617
https://plotly-r.com/shiny-plotly-inputs.html https://plotly-r.com/linking-views-with-shiny.html#shiny-plotly-inputs
1718

1819
https://plotly-r.com/merging-plotly-objects.html https://plotly-r.com/arranging-views.html#arranging-plotly-objects
20+
21+
22+
https://plotly-r.com/interactives/shiny-drag-brush.html https://testing-apps.shinyapps.io/shiny-drag-brush

code/3Devents/app.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
library(plotly)
2+
3+
shiny::shinyAppDir(
4+
system.file(package = "plotly", "examples", "shiny", "event_data_3D")
5+
)

code/discrete-event-data/app.R

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
library(shiny)
2+
library(dplyr)
3+
library(plotly)
4+
5+
ui <- fluidPage(
6+
plotlyOutput("bars"),
7+
verbatimTextOutput("click")
8+
)
9+
10+
classes <- sort(unique(mpg$class))
11+
12+
server <- function(input, output, session) {
13+
14+
output$bars <- renderPlotly({
15+
ggplot(mpg, aes(class, fill = drv, customdata = drv)) + geom_bar()
16+
})
17+
18+
output$click <- renderPrint({
19+
d <- event_data("plotly_click")
20+
if (is.null(d)) return("Click a bar")
21+
mpg %>%
22+
filter(drv %in% d$customdata) %>%
23+
filter(class %in% classes[d$x])
24+
})
25+
26+
}
27+
28+
shinyApp(ui, server)

code/event-priority/app.R

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
library(shiny)
2+
library(plotly)
3+
4+
ui <- fluidPage(
5+
plotlyOutput("p"),
6+
textOutput("time1"),
7+
textOutput("time2")
8+
)
9+
10+
server <- function(input, output, session) {
11+
12+
output$p <- renderPlotly({
13+
plot_ly(x = 1:2, y = 1:2, size = I(c(100, 150))) %>%
14+
add_markers()
15+
})
16+
17+
output$time1 <- renderText({
18+
event_data("plotly_click")
19+
paste("Input priority: ", Sys.time())
20+
})
21+
22+
output$time2 <- renderText({
23+
event_data("plotly_click", priority = "event")
24+
paste("Event priority: ", Sys.time())
25+
})
26+
27+
}
28+
29+
shinyApp(ui, server)

code/interactive-lm/app.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
library(plotly)
2+
3+
shiny::shinyAppDir(
4+
system.file(package = "plotly", "examples", "shiny", "drag_markers")
5+
)

code/plotlyEvents/app.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
library(plotly)
2+
3+
shiny::shinyAppDir(
4+
system.file(package = "plotly", "examples", "shiny", "event_data")
5+
)

code/shiny-corrplot/app.R

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
library(shiny)
2+
library(plotly)
3+
4+
# cache computation of the correlation matrix
5+
correlation <- round(cor(mtcars), 3)
6+
7+
ui <- fluidPage(
8+
plotlyOutput("heat"),
9+
plotlyOutput("scatterplot")
10+
)
11+
12+
server <- function(input, output, session) {
13+
14+
output$heat <- renderPlotly({
15+
plot_ly(source = "heat_plot") %>%
16+
add_heatmap(
17+
x = names(mtcars),
18+
y = names(mtcars),
19+
z = correlation
20+
)
21+
})
22+
23+
output$scatterplot <- renderPlotly({
24+
# if there is no click data, render nothing!
25+
clickData <- event_data("plotly_click", source = "heat_plot")
26+
if (is.null(clickData)) return(NULL)
27+
28+
# Obtain the clicked x/y variables and fit linear model to those 2 vars
29+
vars <- c(clickData[["x"]], clickData[["y"]])
30+
d <- setNames(mtcars[vars], c("x", "y"))
31+
yhat <- fitted(lm(y ~ x, data = d))
32+
33+
# scatterplot with fitted line
34+
plot_ly(d, x = ~x) %>%
35+
add_markers(y = ~y) %>%
36+
add_lines(y = ~yhat) %>%
37+
layout(
38+
xaxis = list(title = clickData[["x"]]),
39+
yaxis = list(title = clickData[["y"]]),
40+
showlegend = FALSE
41+
)
42+
})
43+
44+
}
45+
46+
shinyApp(ui, server)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
library(plotly)
2+
library(nycflights13)
3+
library(colourpicker)
4+
library(ggstat)
5+
6+
shiny::shinyAppDir(
7+
system.file(package = "plotly", "examples", "shiny", "crossfilter_compare")
8+
)

code/shiny-crossfilter-kde/app.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
library(plotly)
2+
3+
shiny::shinyAppDir(
4+
system.file(package = "plotly", "examples", "shiny", "crossfilter_kde")
5+
)

code/shiny-crossfilter-naive/app.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
library(shiny)
2+
library(plotly)
3+
library(dplyr)
4+
library(nycflights13)
5+
6+
ui <- fluidPage(
7+
plotlyOutput("arr_time"),
8+
plotlyOutput("dep_time")
9+
)
10+
11+
server <- function(input, output, session) {
12+
13+
output$arr_time <- renderPlotly({
14+
p <- plot_ly(flights, x = ~arr_time, source = "arr_time")
15+
16+
brush <- event_data("plotly_brushing", source = "dep_time")
17+
if (is.null(brush)) return(p)
18+
19+
p %>%
20+
filter(between(dep_time, brush$x[1], brush$x[2])) %>%
21+
add_histogram()
22+
})
23+
24+
output$dep_time <- renderPlotly({
25+
p <- plot_ly(flights, x = ~dep_time, source = "dep_time")
26+
27+
brush <- event_data("plotly_brushing", source = "arr_time")
28+
if (is.null(brush)) return(p)
29+
30+
p %>%
31+
filter(between(arr_time, brush$x[1], brush$x[2])) %>%
32+
add_histogram()
33+
})
34+
35+
}
36+
37+
shinyApp(ui, server)

0 commit comments

Comments
 (0)