Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File too big when using plotly::api_create and ggplot2::geom_sf functions

I am trying to make online plotting of spatial data using plotly in R but I got an error message "Request Entity Too Large This file is too big! Your current subscription is limited to 524 KB uploads." Any clue about how to solve that? In oder to reproduce my code, you need to (i) register on plotly and (ii) download shapefiles of French departments available on my github repo. The 3 files should be in a folder that is named shapefile. It seems to me that is the ggplot2 function geom_sf that produces files that are too large. My code is below

require(tidyverse)
require(ggplot2)

#Info required for online plotting 
Sys.setenv("plotly_username"="replace_by_your_username")
Sys.setenv("plotly_api_key"="replace_by_your_apikey")

#Read shapefile
dep <- sf::st_read("replace_with_the_correctPATH/shapefile/DEPARTEMENT.shp")

#Variable to plot
zz<-runif(length(dep$CODE_DEPT),-10,3)

#ggplot2 object
gg <- dep %>%
mutate(discrete = cut(zz, c(-10, seq(-3, 3, by = 1)))) %>%
ggplot() +
geom_sf(aes(fill = discrete, text = paste("Department:", dep$CODE_DEPT, "<br>", "bli", zz))) +
scale_fill_brewer(palette = "PuOr", name = "bla")

#Plotting the figure on your local computer works
#plotly::ggplotly(gg, tooltip = c("text"))

#Generate an error message
plotly::api_create(gg, tooltip = c("text"),filename = "sthing")
like image 783
Michael Blum Avatar asked Jun 02 '26 15:06

Michael Blum


1 Answers

This doesn't appear to be your issue but I experienced the same thing. For future readers, my issue seemed to be that the dataframe I was using (say, 100 rows) was subset from a large dataset (15,000 rows) which was larger than the file limit.

Although my subset was quite small and well within the upload limit, I had to save the subset as a csv, load it back in and use that new loaded dataframe as my plotly upload. Even though the imported dataframe was the same row count as the subset dataframe, I had to break the subset connection to the original larger dataset, don't know why.

like image 166
Josh Flori Avatar answered Jun 05 '26 03:06

Josh Flori



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!