plotly / plotly/plotly.R

Cannot have more than one shape after subplot()

Open
#1,869 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

I guess this is related to #1333

Here is the issue: it doesn't seem possible to have more than one shape after subplot() is called. Applying the shapes to the individual plots work, though.

reprex that works:

library(plotly)

p1 <- plot_ly(mtcars, x = ~mpg, y = ~hp) %>% 
  layout(
    shapes = list(
      list(
        type = "line", 
        line = list(color = "#5681c4", dash = "dot"),
        x0 = 20, 
        x1 = 20,
        y0 = 0,
        y1 = 1,
        yref = "paper"
      ),
      list(
        type = "line", 
        line = list(color = "#5681c4", dash = "solid"),
        x0 = 30, 
        x1 = 30,
        y0 = 0,
        y1 = 1,
        yref = "paper"
      )
    )
  ) %>%
  config(editable = TRUE)

p2 <- plot_ly(mtcars, x = ~mpg, y = ~drat) %>% 
  layout(
    shapes = list(
      list(
        type = "line", 
        line = list(color = "#5681c4", dash = "dot"),
        x0 = 20, 
        x1 = 20,
        y0 = 0,
        y1 = 1,
        yref = "paper"
      ),
      list(
        type = "line", 
        line = list(color = "#5681c4", dash = "solid"),
        x0 = 30, 
        x1 = 30,
        y0 = 0,
        y1 = 1,
        yref = "paper"
      )
    )
  ) %>%
  config(editable = TRUE)

subplot(p1, p2, nrows = 2)

reprex that does not work:

library(plotly)

p1 <- plot_ly(mtcars, x = ~mpg, y = ~hp)

p2 <- plot_ly(mtcars, x = ~mpg, y = ~drat)

subplot(p1, p2, nrows = 2) %>% 
  layout(
    shapes = list(
      list(
        type = "line", 
        line = list(color = "#5681c4", dash = "dot"),
        x0 = 20, 
        x1 = 20,
        y0 = 0,
        y1 = 1,
        yref = "paper"
      ),
      list(
        type = "line", 
        line = list(color = "#5681c4", dash = "solid"),
        x0 = 30, 
        x1 = 30,
        y0 = 0,
        y1 = 1,
        yref = "paper"
      )
    )
  ) %>%
  config(editable = TRUE)

reprex with only one shape - it works:

library(plotly)

p1 <- plot_ly(mtcars, x = ~mpg, y = ~hp)

p2 <- plot_ly(mtcars, x = ~mpg, y = ~drat)

subplot(p1, p2, nrows = 2) %>% 
  layout(
    shapes = list(
      type = "line", 
      line = list(color = "#5681c4", dash = "dot"),
      x0 = 20, 
      x1 = 20,
      y0 = 0,
      y1 = 1,
      yref = "paper"
    )
  ) %>%
  config(editable = TRUE)

Any thoughts?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the working and failing reprexes in the issue, comparing shapes supplied to each plot with shapes added after subplot(). Trace how subplot() combines the plots and how the later layout(shapes = ...) call is handled. Done means both shapes render on the subplot and remain editable with config(editable = TRUE).

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.