Pluto on Binder: use a repo environment rather than Pluto managed environment?

I would like to load a Pluto notebook in Binder that uses an environment managed outside the notebook itself (but in the same repository).

Is this possible somehow to swing using the raw URL for a Pluto notebook in a remote repo?

E.g., my first cell says:

begin
	using Pkg
	Pkg.activate(".")
	Pkg.instantiate()
	using PlutoUI
end

Using https://pluto-on-binder.glitch.me/, it doesn’t know how to find the Project/Manifest files and thus the version of PlutoUI I want to manage from there.

Don’t know how binder runs the notebook, but could you just clone the repo in the first cell to some local path and then activate that path?

It makes sense to me to be able to download the Manifest.toml and Project.toml files to a local temp directory and activate from there, but I can’t figure out how to do that … see this related question I just posted.

I’m trying with this code in the first cell to download config files to a temp directory:

begin
	using Downloads
	using Pkg

	owd = pwd()

	if isfile(joinpath("..","Manifest.toml")) && isfile(joinpath("..","Project.toml"))

		cd("..")
		Pkg.activate(".")
		Pkg.resolve()
		Pkg.instantiate()
		cd(owd)
		
	elseif isfile(joinpath(".","Manifest.toml")) && isfile(joinpath(".","Project.toml"))

		Pkg.activate(".")
		Pkg.resolve()
		Pkg.instantiate()
		
	else

		manifest_url = "https://URL/to/Manifest.toml"
		project_url = "https://URL/to/Project.toml"
		
		temp_dir = mktempdir(".",cleanup=true)
		
		Downloads.download(manifest_url,joinpath(owd,temp_dir,"Manifest.toml"))
		Downloads.download(project_url,joinpath(owd,temp_dir,"Project.toml"))
		
		cd(temp_dir)
		
		Pkg.activate(".")
		Pkg.instantiate()
		
		cd(owd)
	end

end

In some projects, I have these files in a folder just above the notebook. In others, I have them in the same folder. If it’s running on Binder, they won’t be in either location, so we can make a temp directory and download them from the repository, then activate and instantiate on that directory.

It works well locally and on Binder on simple test cases, but on my real notebook, I’m getting this error running the notebook on Binder:

expected package `QOI [4b34888f]` to be registered

    pkgerror(::String)@Types.jl:55
    check_registered(::Pkg.Types.Context, ::Vector{Pkg.Types.PackageSpec})@Operations.jl:1157
    var"#instantiate#253"(::Nothing, ::Bool, ::Bool, ::Base.BinaryPlatforms.Platform, ::Bool, ::Bool, ::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(Pkg.API.instantiate), ::Pkg.Types.Context)@API.jl:1372
    instantiate@API.jl:1325[inlined]
    #instantiate#252@API.jl:1321[inlined]
    instantiate()@API.jl:1321
    top-level scope@

Some solutions suggest deleting the registry to fix it, but I can’t do that on Binder.

Or to update the registry with Pkg.Registry.update(). This also did not solve it.

I tried deleting the Manifest.toml and runing pkg> instantiate again to make it fresh, but that yields the same error.

Linking to newly created issues on QOI and Pluto on Binder (don’t know if these are the issue or not).

What Julia version are you using? Can you see if QOI.jl is present in the downloaded registry? This folder should exist General/Q/QOI at master · JuliaRegistries/General · GitHub.

With Pluto on Binder, it’s running Julia 1.6.3. I created the manifest locally for a project with the header, which I download from a remote repo:

# This file is machine-generated - editing it directly is not advised

julia_version = "1.7.1"
manifest_format = "2.0"

When I do `Pkg.add(“QOI”), it seems to get past it (to proceed to other errors with other packages…) but I’d like to figure out how to get it to load correclty straight from the manifest if possible.

The site https://pluto-on-binder.glitch.me/ was still using an old version of Julia and Pluto. I just updated, try again!

The example notebook uses Pkg to set up a package environment, because it was written before 🎁 Package management · fonsp/Pluto.jl Wiki · GitHub existed! You should definitely use the built-in package manager for binder, which will also fix this issue.

1 Like