Plotly map does not display in viewer pane

Continuing from: Creating a map by R-Studio

Thank you! Jcblum,

I run the code by RGui and got the map successfully, but why it doesn't work in R-Studio?

When you say it doesn't work, what exactly is not working? (I ran the code above in RStudio and everything worked as expected)

I just got the measure bar, the map doesn't show up.

@Visiting, have you tried hovering over the area where the map should be and clicking on the 'white area'.

I know, at least for me, that when I'm using plotly I usually have to click the white space where the map should be for the image to show up.

@Hlynur I did, no map show up, only the measure bar in the viewer window. Thanks.

I've split this out into a new topic, since it seems to be a separate issue. Can you confirm a few things?

  1. What is the exact code you are running?

  2. Some information about your system would be helpful:

    • The output of running sessionInfo() after you've run the code that makes the map
    • The output of running rstudioapi::versionInfo()

The code is exact the same, listed below:

library(plotly)
mh <- data.frame(
  rank = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
           19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
           31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
           43, 44, 45, 46, 47, 48, 49, 50, 51),
  state = c("CT", "MA", "VT", "SD", "MN", "NJ", "IA", "ND", "PA", "ME",
            "DE", "NY", "AK", "MD", "IL", "HI", "MI", "DC",
            "KY", "NH", "KS", "NM", "CA", "OK", "CO", "OH",
            "NE", "FL", "WY", "WA", "MO", "TX", "NC", "GA",
            "WI", "RI", "SC", "VA", "MT", "UT", "TN", "LA",
            "WV", "MS", "IN", "AL", "AR", "ID", "OR", "AZ",
            "NV")
)

plot_ly(
  type = "choropleth",
  locations = mh$state,
  locationmode = "USA-states",
  z = mh$rank
) %>%
  layout(geo = list(scope = "usa"))

scale%20bar
Here is the output, only scale bar displayed in the viewer window, no map.

Here is sessionInfo()

########################################################
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
[1] bindrcpp_0.2.2 plotly_4.8.0   ggplot2_3.0.0 

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17      bindr_0.1.1       magrittr_1.5      tidyselect_0.2.4 
 [5] munsell_0.4.3     xtable_1.8-2      viridisLite_0.3.0 colorspace_1.3-2 
 [9] R6_2.2.2          rlang_0.2.1       httr_1.3.1        plyr_1.8.4       
[13] dplyr_0.7.5       tools_3.5.0       grid_3.5.0        data.table_1.11.4
[17] gtable_0.2.0      withr_2.1.2       crosstalk_1.0.0   htmltools_0.3.6  
[21] yaml_2.1.19       lazyeval_0.2.1    assertthat_0.2.0  digest_0.6.15    
[25] tibble_1.4.2      shiny_1.1.0       later_0.7.3       tidyr_0.8.1      
[29] purrr_0.2.5       promises_1.0.1    htmlwidgets_1.2   mime_0.5         
[33] glue_1.2.0        compiler_3.5.0    pillar_1.2.3      scales_0.5.0     
[37] jsonlite_1.5      httpuv_1.4.3      pkgconfig_2.0.1  
> rstudioapi::versionInfo()
############################################################
$`citation`

To cite RStudio in publications use:

  RStudio Team (2016). RStudio: Integrated Development for R. RStudio,
  Inc., Boston, MA URL http://www.rstudio.com/.

A BibTeX entry for LaTeX users is

  @Manual{,
    title = {RStudio: Integrated Development Environment for R},
    author = {{RStudio Team}},
    organization = {RStudio, Inc.},
    address = {Boston, MA},
    year = {2016},
    url = {http://www.rstudio.com/},
  }

$`mode`
[1] "desktop"

$version
[1] ‘1.1.383’

Thank you!

Hmm, so I cannot replicate this on RStudio Cloud (R 3.5.0, RStudio Server Pro 1.2.747.3) — everything works fine there as you can see in this shared project:
https://rstudio.cloud/project/51112

However, on a system that's running R 3.3.3 and RStudio 1.1.447, I can replicate the problem. No map, just the scale bar. This is not a perfect analog for your situation, since you are running a substantially newer R and on a different OS than my old system.

I am noticing that your RStudio is not the current release (you have 1.1.383, while the current release is 1.1.456. There is also a preview release of 1.2 available (https://www.rstudio.com/products/rstudio/download/preview/) — running this would be close to the RStudio Cloud setup where we know the problem does not occur.

So perhaps try updating your RStudio to the preview release and see if that helps?

2 Likes

Upgraded R-Studio to preview release of 1.2, now it works well.
Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

1 Like

Great! Happy mapping :grin:

A post was split to a new topic: Help creating a map

By default, the choropleth trace type in plotly relies on an internet connection. I have a feeling this was the real underlying issue. Use the offline argument in plot_geo() if you'd like to create a map that renders without an internet connection.

library(plotly)

map_data("world", "canada") %>%
    group_by(group) %>%
    plot_geo(x = ~long, y = ~lat, offline = TRUE) %>%
    add_polygons(span = I(1))
2 Likes

I have exactly the same issue. It works in new window not in viewer. I've just installed the latest version:

> rstudioapi::versionInfo()
$citation

To cite RStudio in publications use:

  RStudio Team (2016). RStudio: Integrated Development for R. RStudio, Inc., Boston, MA URL
  http://www.rstudio.com/.

A BibTeX entry for LaTeX users is

  @Manual{,
    title = {RStudio: Integrated Development Environment for R},
    author = {{RStudio Team}},
    organization = {RStudio, Inc.},
    address = {Boston, MA},
    year = {2016},
    url = {http://www.rstudio.com/},
  }


$mode
[1] "desktop"

$version
[1] ‘1.1.463’

About offline I get:
Warning message: 'choropleth' objects don't have these attributes: 'offline'

packageVersion('plotly')
[1] ‘4.7.1’

sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=Polish_Poland.1250 LC_CTYPE=Polish_Poland.1250 LC_MONETARY=Polish_Poland.1250
[4] LC_NUMERIC=C LC_TIME=Polish_Poland.1250

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

other attached packages:
[1] bindrcpp_0.2.2 stringr_1.3.1 openxlsx_4.0.17 plotly_4.7.1 ggplot2_2.2.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 RColorBrewer_1.1-2 pillar_1.3.0 later_0.7.1 plyr_1.8.4
[6] bindr_0.1.1 tools_3.3.3 digest_0.6.14 jsonlite_1.5 tibble_1.4.2
[11] gtable_0.2.0 viridisLite_0.1.3 pkgconfig_2.0.1 rlang_0.2.0 shiny_1.0.0
[16] rstudioapi_0.7 crosstalk_1.0.0 yaml_2.1.14 dplyr_0.7.4 httr_1.3.1
[21] htmlwidgets_1.3 grid_3.3.3 glue_1.2.0 data.table_1.10.4-3 R6_2.2.2
[26] purrr_0.2.4 tidyr_0.8.0 magrittr_1.5 promises_1.0.1 scales_0.5.0
[31] htmltools_0.3.5 assertthat_0.2.0 xtable_1.8-2 mime_0.5 colorspace_1.3-2
[36] httpuv_1.4.1 stringi_1.1.7 lazyeval_0.2.0 munsell_0.5.0 crayon_1.3.4

Updating plotly will likely fix your issue:

install.packages('plotly')