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

Width of plot output too small when plot is rendered in the background #491

Open
DavZim opened this issue Nov 29, 2022 · 7 comments
Open
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@DavZim
Copy link

DavZim commented Nov 29, 2022

When the user clicks on a tab 1 with an echarts4r plot and then moves on to another tab 2 before tab 1 has finished rendering it, the plot on tab 1 will have an incorrect width.

MWE

Given the following app:

  1. Start the app
  2. Click on tab Plot1 then immediately go to tab Plot2
  3. Wait until Plot2 is rendered (so that Plot1 is rendered in the background)
  4. goto Plot1 and you see that the plot does not cover the whole width of the screen until the window is resized.
library(shiny)
library(echarts4r)

ui <- fluidPage(
  tabsetPanel(
    tabPanel("Origin"),
    tabPanel("Plot1", echarts4rOutput("plot1")),
    tabPanel("Plot2", echarts4rOutput("plot2"))
  )  
)

server <- function(input, output, session) {
  output$plot1 <- renderEcharts4r({
    Sys.sleep(1)
    df <- data.frame(
      x = seq(50),
      y = rnorm(50, 10, 3)
    )
    df |> 
      e_charts(x) |> 
      e_line(y)
  })
  
  output$plot2 <- renderEcharts4r({
    Sys.sleep(1)
    df <- data.frame(
      x = seq(20),
      y = rnorm(20, 10, 3)
    )
    df |> 
      e_charts(x) |> 
      e_area(y)
  })
}

shinyApp(ui, server)

This is what I see:
image

This is what I expect to see (which is what I see when I wait until plot1 is rendered before moving on or when I resize the window):
image

@helgasoft
Copy link
Contributor

Using width like echarts4rOutput("plot1", width=999) is not responsive, but helps.

@JohnCoene
Copy link
Owner

It should be responsive I'm surprised it's not right. Shouldn't tabPanel call the resize event when a tab is toggled? That is implemented in echarts4r

@JohnCoene
Copy link
Owner

You could use resize proxy but really should not have to

@DavZim
Copy link
Author

DavZim commented Nov 30, 2022

I tried the above code but used a static ggplot instead and the resizing issue does not appear.

@munoztd0 munoztd0 pinned this issue Jun 12, 2023
@munoztd0 munoztd0 self-assigned this Aug 24, 2023
@munoztd0 munoztd0 added the bug Something isn't working label Aug 24, 2023
@VIRADUS
Copy link

VIRADUS commented Feb 22, 2024

Any updates on this issue? This behavior happens in Echarts4r Shiny demo as well.

In the Loading tab, click on "Generate" and then switch to a different tab while it renders in the background. When you return, this happens:

image

@munoztd0 munoztd0 added the help wanted Extra attention is needed label Feb 23, 2024
@munoztd0
Copy link
Collaborator

Hello, yeah that's a problem, I'm working on it but I think it has to do with htmlwidgets, ... gonna try to find the issue

@JohnCoene
Copy link
Owner

Yes, I don't think it's on echarts4r's end. I suspect it's a combination of shiny and htmlwidgets.

The graph is initialised with the wrong width and the only way this gets redrawn is with if a resize event gets fired and it does not.

I don't fully understand why it gets initialised with the wrong width.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants