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

Version 4.9.0 does not display properly with Flexdashboard #1546

Closed
enricodata opened this issue Jun 9, 2019 · 11 comments
Closed

Version 4.9.0 does not display properly with Flexdashboard #1546

enricodata opened this issue Jun 9, 2019 · 11 comments

Comments

@enricodata
Copy link

Version 4.9.0 does not display properly with Flexdashboard

Here you can find an example:
https://community.rstudio.com/t/plotly-does-not-display-in-flexdashboard-page/32696

I solved it by deleting the version 4.9.0 and by using the version 4.8.0

@cpsievert
Copy link
Collaborator

cpsievert commented Jun 10, 2019

Here's the JS stacktrace --

Screen Shot 2019-08-30 at 2 09 15 PM

This is very likely a plotly.js bug. We'll have to come up with a more minimal example before reporting to the plotly.js team

(Update: see #1546 (comment) for a workaround)

@guivo
Copy link

guivo commented Jun 21, 2019

Are there news about this issue? I have the same problem in a complex dashboard, that unfortunately I cannot share at the moment.

I have tried to manually update the plotly-latest,min.js file within the htmlwidgets, but this didn't change the behaviour.

In particular, the dashboard I generate is fine when I open it. If I try to refresh the page, the error occurs and plots aren't rendered.

@eightsixtwo
Copy link

I also have this issue... If I run the code, rather than knit, the interactive plot appears in the viewer and seems fine. However if I knit the code then the plotly plot does not appear at all.

@guivo
Copy link

guivo commented Aug 8, 2019

I have made a minimal example that show the problem.

To note that if the geom_hex() in the 2nd page is replace by geom_line() or other 2d primitive everything is rendered properly.

The problem is also fixed reverting to version 4.8.

debug_plotly49.zip

@jenzopr
Copy link

jenzopr commented Aug 22, 2019

Here is another minimal example:

---
output:
  flexdashboard::flex_dashboard:
    theme: yeti
---

Page 1
====================================================

Column
----------------------------------------------------

###

Page 2
====================================================

Column
-------------------------------------

### 

```{r}
plotly::plot_ly(mtcars, x = ~mpg, y = ~wt, color = ~qsec)
```x

Please remove the terminal x before running the code - this is only to enable proper rendering of the code in this comment.

@cpsievert
Copy link
Collaborator

cpsievert commented Aug 30, 2019

Looks like you can workaround this problem by adding config(p, fillFrame = TRUE) to any plot p that isn't shown on initial load

@Finesim97
Copy link

This seems to affect not only heat maps, but any plot with polygons.

Looks like you can workaround this problem by adding config(p, fillFrame = TRUE) to any plot p that isn't shown on initial load

But that appears to break scrollable layouts? (Will try to provide an example), the axis scaling also breaks when you produce the "polygon" plots with tagList

```{r,results="asis",eval=F}

constructPlot <-function(mat)htmltools::tagList(list(a=plot_ly(z=mat,type = "heatmap",colors = "Greys")))
plots <- lapply(qualmat_raw,function(sample)lapply(sample,constructPlot))
for(samplename in names(qualmat_raw)){
  cat("\nRow\n--------------------------------------\n")
  cat(paste0("\n\n### Quality Occurence Heatmap: ",samplename," R1","\n\n"))
  print(plots[[samplename]][["R1"]])
  cat(paste0("\n\n### Quality Occurence Heatmap: ",samplename," R2","\n\n"))
  print(plots[[samplename]][["R2"]])
}

```x

The 4.8 revert also fixes this.

Have a nice day you all and thanks for your work,
Lukas Jansen

@cpsievert
Copy link
Collaborator

This issue should be fixed now in the dev version -- remotes::install_github("ropensci/plotly")

Also, a CRAN release will be coming by the end of next week

@arsenij-ust
Copy link

Hi all,
unfortunately, the error still exists.
I used the minimal example from above jenzopr.
The JS stacktrace:
js_error

You can use the following Docker container for reproduction:
https://gitlab.gwdg.de/loosolab/container/i2dash.development

Rendered the minimal example Rmd with rmarkdown::render()

The offered workaround is unfortunately not suitable for our purposes, because we cannot know if the flexdashboard component will be on the first page and if it will fill the full page.

@arsenij-ust
Copy link

Workarounds, that work well for me:

p_env <- plotly::plot_ly(mtcars, x = ~mpg, y = ~wt, color = ~qsec) %>%
  plotly::layout(autosize = F, yaxis = list(automargin = T), xaxis = list(automargin = T)) %>% 
  htmlwidgets::onRender("
                        function(el, x) {
                        // workaround for plotly.js (https://github.com/ropensci/plotly/issues/1546)
                          // get size of parents div container
                          document.getElementById('scatter_env').parentElement.id = 'parent_scatter_env'
                          var clientHeight = document.getElementById('parent_scatter_env').clientHeight;
                          var clientWidth = document.getElementById('parent_scatter_env').clientWidth;
                          
                          // avoid errors at 0 width and height
                          if (clientHeight === 0){
                            clientHeight = 450 // plotly's default value 
                          }
                          if (clientWidth === 0){
                            clientWidth = 700 // plotly's default value 
                          }
                          
                          // get current layout and relayout plotly chart
                          var layout = el.layout;
                          layout.height = clientHeight;
                          layout.width = clientWidth;
  
                          Plotly.relayout(el, layout)
                        }
                        ")
p_env$elementId <- "scatter_env"
p_env

If the flexdashboard uses Shiny (with runtime: shiny), then we can embed the plotly output in renderUI function:
shiny::renderUI({plotly::plotlyOutput("plot", height = "100%")})

I would be glad to see possible improvements and optimizations of the code.

@DeLaRiva
Copy link

I guess it is still open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants