Skip to content

export() doesn't work properly with choropleth maps #840

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

Closed
salim-b opened this issue Jan 2, 2017 · 2 comments
Closed

export() doesn't work properly with choropleth maps #840

salim-b opened this issue Jan 2, 2017 · 2 comments

Comments

@salim-b
Copy link
Contributor

salim-b commented Jan 2, 2017

If I try to export any choropleth map using plotly's export() function, the map itself is missing in the resulting PNG file. For example feeding the map produced by the following code from plotl.ly

library(plotly)
df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv")
df$hover <- with(df, paste(state, '<br>', "Beef", beef, "Dairy", dairy, "<br>",
                           "Fruits", total.fruits, "Veggies", total.veggies,
                           "<br>", "Wheat", wheat, "Corn", corn))
# give state boundaries a white border
l <- list(color = toRGB("white"), width = 2)
# specify some map projection/options
g <- list(
  scope = 'usa',
  projection = list(type = 'albers usa'),
  showlakes = TRUE,
  lakecolor = toRGB('white')
)

p <- plot_geo(df, locationmode = 'USA-states') %>%
  add_trace(
    z = ~total.exports, text = ~hover, locations = ~code,
    color = ~total.exports, colors = 'Purples'
  ) %>%
  colorbar(title = "Millions USD") %>%
  layout(
    title = '2011 US Agriculture Exports by State<br>(Hover for breakdown)',
    geo = g
  )

to the export() function produces this raster image:
p

I don't know if this problem is related to the current need of an internet connection to produce maps (I mean somewhere internally; of course I have an active internet connection when exporting the map). At least with scatter and bar plots the export works as supposed.

I'm using plotly 4.5.6 with R 3.3.2 on Ubuntu Linux 16.04 LTS.

@cpsievert
Copy link
Collaborator

It appears that giving it some time to load the external resources fixes the problem. To do so, use the delay argument (from webshot())

export(p, delay = 2)

@salim-b
Copy link
Contributor Author

salim-b commented Mar 9, 2017

It appears that giving it some time to load the external resources fixes the problem. To do so, use the delay argument (from webshot())

Thanks for the hint, this works indeed! I guess it would make sense to have this mentioned in the corresponding tutorial.

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

2 participants