Skip to content

Commit 51a9357

Browse files
committed
economics restyle example
1 parent 74e1d40 commit 51a9357

File tree

3 files changed

+41
-0
lines changed
  • inst/examples/shiny

3 files changed

+41
-0
lines changed

inst/examples/shiny/proxy_mapbox/app.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
library(shiny)
2+
library(plotly)
23

34
# get all the available mapbox styles
45
mapStyles <- schema()$layout$layoutAttributes$mapbox$style$values

inst/examples/shiny/proxy_restyle_canada/app.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
library(shiny)
2+
library(plotly)
23

34
ui <- fluidPage(
45
selectInput("color", "Canada's fillcolor", colors(), selected = "black"),
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
library(shiny)
2+
library(plotly)
3+
4+
ui <- fluidPage(
5+
sliderInput("marker", "Marker size", min = 0, max = 20, value = 5),
6+
sliderInput("path", "Path size", min = 0, max = 30, value = 10),
7+
plotlyOutput("p")
8+
)
9+
10+
server <- function(input, output, session) {
11+
12+
output$p <- renderPlotly({
13+
plot_ly(
14+
economics, x = ~pce, y = ~psavert, z = ~unemploy,
15+
color = ~as.numeric(date), mode = "markers+lines"
16+
)
17+
})
18+
19+
observeEvent(input$marker, {
20+
plotlyProxy("p", session) %>%
21+
plotlyProxyInvoke(
22+
"restyle",
23+
# could also do list(marker = list(size = input$marker))
24+
# but that overwrites the existing marker definition
25+
# https://github.com/plotly/plotly.js/issues/1866#issuecomment-314115744
26+
list(marker.size = input$marker)
27+
)
28+
})
29+
30+
observeEvent(input$path, {
31+
plotlyProxy("p", session) %>%
32+
plotlyProxyInvoke(
33+
"restyle", list(line.width = input$path)
34+
)
35+
})
36+
37+
}
38+
39+
shinyApp(ui, server)

0 commit comments

Comments
 (0)