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

leafletProxy doesn't work with htmlwidgets_0.6 and shinydashboard #242

Closed
byzheng opened this issue Feb 26, 2016 · 9 comments
Closed

leafletProxy doesn't work with htmlwidgets_0.6 and shinydashboard #242

byzheng opened this issue Feb 26, 2016 · 9 comments

Comments

@byzheng
Copy link
Contributor

byzheng commented Feb 26, 2016

it seem function leafletProxy is not working in htmlwidgets_0.6. the error message in console is

Couldn't find map with id map

I used the second example in this page: https://rstudio.github.io/leaflet/shiny.html

The latest version in the github has the same problem.

The htmlwidgets_0.5 is working fine with leafletProxy

@jcheng5
Copy link
Member

jcheng5 commented Feb 26, 2016

Thanks for the heads up, I'll investigate.

@jcheng5
Copy link
Member

jcheng5 commented Feb 26, 2016

I think I've fixed it. Can you try it again with one of these two builds?

devtools::install_github("rstudio/leaflet")  # for latest (unstable)

or

devtools::install_github("rstudio/leaflet@joe/bugfix/htmlwidgets_0.6")  # for CRAN patch (stable)

@byzheng
Copy link
Contributor Author

byzheng commented Feb 26, 2016

Thanks for your quick fix. It's working now for htmlwidgets_0.6

However, I find another bug for shinydashboard. You can find a minimum example from here: https://gist.github.com/byzheng/4dc969043439bf44217d

  • app1.R adds leafletOutput in the same menuItem of Shiny.onInputChange and works fine
  • app2.R adds leafletOutput in the another menuItem of Shiny.onInputChange, but get the same error message (Couldn't find map with id map). PS: I noticed this error doesn't always happen especially click click me several times.

My session infor:

R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

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

other attached packages:
[1] leaflet_1.0.1        shiny_0.13.0         shinydashboard_0.5.1

loaded via a namespace (and not attached):
 [1] htmlwidgets_0.6 magrittr_1.5    R6_2.1.2        tools_3.2.3    
 [5] htmltools_0.3   yaml_2.1.13     Rcpp_0.12.3     jsonlite_0.9.19
 [9] digest_0.6.9    xtable_1.8-2    httpuv_1.3.3    mime_0.4  

@byzheng byzheng changed the title leafletProxy doesn't work with htmlwidgets_0.6 leafletProxy doesn't work with htmlwidgets_0.6 and shinydashboard Feb 26, 2016
@byzheng
Copy link
Contributor Author

byzheng commented Feb 26, 2016

I think I find the reason above error of shinydashboard. When shiny app is opening, the second itemMenu don't draw until the menu is clicked, so it makes sense the leaflet object map cannot find. So my current question is how to force to draw the leaflet map when page load.

@jcheng5
Copy link
Member

jcheng5 commented Feb 27, 2016

On the server side can you try adding outputOptions(output, "map", suspendWhenHidden=FALSE) right after assigning output$map?

@jcheng5
Copy link
Member

jcheng5 commented Feb 27, 2016

I've submitted Leaflet 1.0.1 to CRAN. Thanks again for the report. If the problem with shinydashboard persists, please submit a new issue. Thanks!

@jcheng5 jcheng5 closed this as completed Feb 27, 2016
bbest added a commit to bbest/ohi-shiny2 that referenced this issue May 20, 2016
on FITZ -> ohi-science.nceas.ucsb.edu
solution suggested at rstudio/leaflet#242

```r
outputOptions(output, "map1", suspendWhenHidden=FALSE)
```
@tcash21
Copy link

tcash21 commented Aug 10, 2018

Hi all just as an FYI and hope this is helpful- I had this same issue without shinydashboard when trying to render a 2nd leaflet map on a separate tab. Tried updating leaflet, but adding outputOptions(output, "map", suspendWhenHidden=FALSE) fixed it.

@illsio
Copy link

illsio commented Feb 6, 2019

Using Leaflet 2.0.2 - I still experience the issue. Adding outputOptions does not fix the issue in my case.

@amruthkiran94
Copy link

Hi all just as an FYI and hope this is helpful- I had this same issue without shinydashboard when trying to render a 2nd leaflet map on a separate tab. Tried updating leaflet, but adding outputOptions(output, "map", suspendWhenHidden=FALSE) fixed it.

Been struggling for a while with this issue. My 2nd map element wouldn't load unless an event was triggered. I'm not entirely sure if this is due to multiple tabs or proxy functions. But this solution works for me. Looks like this works for BS4Dash-based Shiny apps. Pasting relevant session info below:
R version 4.3.1
shiny_1.7.5
bs4Dash_2.3.0
leaflet_2.1.2

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

5 participants