Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with configurable annotations: when repositioning annotation via click and drag, annotation gets duplicated. Seems to be an issue with specifying font attributes. #2409

Open
ellenbouchard opened this issue Dec 11, 2024 · 0 comments

Comments

@ellenbouchard
Copy link

Hello,

I ran into what appears to be a bug with configurable annotations in R. Briefly, if just one annotation label is displayed on the plot, and I reposition the label by clicking and dragging, the annotation gets duplicated; one label is repositioned, and the other remains in its original position. If more than one annotation label is displayed, this does not happen.

After some investigating, I realized that this only happens if the "font" argument within "add_annotations" is a list of more than one element. So if I don't specify any "font" attributes, or specify only one font attribute (such as color or size), the bug does not occur. As soon as I specify multiple font attributes, the bug happens. I realize this may be a version thing but wanted to put it out there regardless.

Example here, code slightly modified from Text and Annotations in R :
This code has a bug; the annotation label will be duplicated when repositioned

library(plotly)

data <- mtcars[which(mtcars$am == 1 & mtcars$gear == 4),]
annot_data <- data[1,]

fig <- plot_ly(data, x = ~wt, y = ~mpg, type = 'scatter', mode = 'markers',
               marker = list(size = 10)) %>% 
              config(editable = TRUE)

fig <- fig %>% add_annotations(x = annot_data$wt,
                               y = annot_data$mpg,
                               text = rownames(annot_data),
                               xref = "x",
                               yref = "y",
                               showarrow = TRUE,
                               arrowhead = 4,
                               arrowsize = .5,
                               ax = 20,
                               ay = -40,
                               # Styling annotation text:
                               font = list(family = 'sans serif',
                                           size = 14))

fig

This code, in which 'font' only has one element, does NOT have the bug; the annotation label will be repositioned normally

library(plotly)

data <- mtcars[which(mtcars$am == 1 & mtcars$gear == 4),]
annot_data <- data[1,]

fig <- plot_ly(data, x = ~wt, y = ~mpg, type = 'scatter', mode = 'markers',
               marker = list(size = 10)) %>% 
              config(editable = TRUE)

fig <- fig %>% add_annotations(x = annot_data$wt,
                               y = annot_data$mpg,
                               text = rownames(annot_data),
                               xref = "x",
                               yref = "y",
                               showarrow = TRUE,
                               arrowhead = 4,
                               arrowsize = .5,
                               ax = 20,
                               ay = -40,
                               # Styling annotation text:
                               font = list(size = 14))

fig

Session info:

R version 4.3.2 (2023-10-31)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.7.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Los_Angeles
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plotly_4.10.4 ggplot2_3.5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant