posit-dev / r-shinylive

https://posit-dev.github.io/r-shinylive/
Other
151 stars 16 forks source link

Error reading gzip files #36

Closed nathanweeks closed 5 months ago

nathanweeks commented 9 months ago

A Shinylive app is able to read from a CSV file, e.g., the shiny 02_text example, altered such that the "rock" data frame is read from a CSV by replacing this comment with a read.csv():

Rscript -e 'system.file("examples", "02_text", package="shiny") |> fs::dir_copy("myapp", overwrite = TRUE)'
Rscript -e 'write.csv(rock, file="myapp/rock.csv")'
sed -i '' 's/# Return the requested.*/rock <- read.csv("rock.csv")/' myapp/app.R
Rscript -e 'shinylive::export("myapp", "site")'
Rscript -e 'library(plumber); pr() |> pr_static("/", "site/") |> pr_run()'

However, when attempting to read from the same CSV that is gzip-compressed:

Rscript -e 'system.file("examples", "02_text", package="shiny") |> fs::dir_copy("myapp", overwrite = TRUE)'
Rscript -e 'write.csv(rock, file=gzfile("myapp/rock.csv.gz"))'
sed -i '' 's/# Return the requested.*/rock <- read.csv("rock.csv.gz")/' myapp/app.R
Rscript -e 'shinylive::export("myapp", "site")'
Rscript -e 'library(plumber); pr() |> pr_static("/", "site/") |> pr_run()'

The following error is observed in the web browser:

Error starting app! Robj construction for this JS object is not yet supported

schloerke commented 9 months ago

@georgestagg Any ideas? I couldn't find in docs that gzip compression is/isn't supported. (Thank you!)

georgestagg commented 9 months ago

The problem is here in the shinylive source. It likely will affect other files encoded in app.json when the file has the type: binary property.

The instantiation of a new RList() object works OK when passing text content to R to be saved to the virtual filesystem, but webR is not expecting a binary object here with a content property of type Uint8Array. That's where the error "Robj construction for this JS object is not yet supported" is coming from.

A small tweak will be required to handle that case better. Probably the Uint8Array content should be created in R as a raw() R object. I'll take a look at it when I can.

schloerke commented 9 months ago

There is a workaround for now. So no immediate rush. Thank you!

maek-ies commented 7 months ago

There is a workaround for now. So no immediate rush. Thank you!

Dear Barret, could you please specify what the workaround is to allow use of gzip files in shinylive?

I understand that fix by George is yet to be pulled into main shinylive code as the code above still results in the error ("Robj construction for this JS object is not yet supported") and that's why this issue is still open, right?

georgestagg commented 5 months ago

This should now work OK.

Please let me know if binary files (e.g. compressed data) are still unable to be exported as part of a Shiny app in a reply below and I can re-open the issue.