JuliaPluto / PlutoUI.jl

https://featured.plutojl.org/basic/plutoui.jl
The Unlicense
299 stars 54 forks source link

[WIP] Getting data from local resource #297

Open alhirzel opened 4 months ago

alhirzel commented 4 months ago

What is the best way to get data from a LocalResource?

For my application, I am treating a Pluto notebook just like a Julia script, and am packaging it alongside some data that is being analyzed. The files are small-medium size, so the data: URI technique employed by this package is an ideal fit for export to HTML later.

One of the files is a .csv file, and I need to parse it. Currently, I am doing something like this with the help of a new method currently in this PR as a straw-man:

f = PlutoUI.LocalResource("data.csv")
d = CSV.read(Vector{UInt8}(f), DataFrame)

(One problem with this approach is that it will only work for Resources that are generated using the LocalResource function; perhaps the type should be forked?)

Happy to implement something and propose it here, but I am wondering if there are better ways to do what I am trying to do. Ideas:

  1. integrate with the FileIO.jl package
  2. use the PlutoUI.as_text function in a way I don't yet understand
  3. use something like the RelocatableFolders.jl package (a la PackageCompiler)
  4. use another approach not involving LocalResource - e.g. if it is going to be deprecated or externalized in the future
github-actions[bot] commented 4 months ago

Try this Pull Request!

Open Julia and type:

  julia> import Pkg
julia> Pkg.activate(temp=true)
julia> Pkg.add(url="https://github.com/alhirzel/PlutoUI.jl", rev="data-from-LocalResources")
julia> using PlutoUI

Or run this code in your browser: Run with binder

fonsp commented 2 months ago

Hey @alhirzel !

Sorry I missed your message before!

Can you write a bit more about why you cannot access the files normally? E.g.

CSV.read(read("data.csv"), DataFrame)