"importing" other livebooks in a livebook?

My googling so far has failed me, but is there a way to import another .livemd in a livebook?

I’m working on an algorithm impl, and while doing that, have lots of visualization code that’d like to banish from the main notebook, but not create an elixir app, as I the visualizations themselves need debugging that’s done in the notebook, and from past experience having stuff in an elixir app creates significant friction with having to switch editors all the time, etc.

2 Likes

If I understand correctly - you have code related to building visualizations, and code for an algorithm, and you’d like to have all the code directly in LiveBook, but not in the same .livemd file?

I’ve seen people use “Sections” to organize code within a single .livemd file, and I’ve seen people create multiple .livemd files within a directory and link between them. I haven’t seen anything quite like your import idea, but I wonder if using Embedded Mode or Attached Mode would work???

This blog post from AppSignal describes each of the available modes. I haven’t tried embedded at all, but the remark that “code defined in one notebook may interfere with code from another notebook” makes me curious.

Given that LiveBook is essentially a Phoenix application, I also wonder if you could use Attached Mode to connect two running LiveBooks to each other?

Maybe you could start an instance of Elixir and then attach that node to two different livebooks? Screenshot attached of the sidebar button to press and dialog to fill in the two livebooks.

If this worked this wouldn’t solve having to tab between windows, but you’d have the same state/modules available in both and perhaps two browser tabs is less cumbersome than different apps.

I think there may be some hidden complexity here, but I like the idea of being able to add other .livemd files as dependencies in the setup block. I’ve been really enjoying using LiveBook as a sort of advanced REPL for a Phoenix app I’m working on, but there’s a decent amount of setup that I’d like to be able to share between multiple notebooks that I’d prefer not to duplicate. Right now I have a lib/livebook that contains utilities but it would be nice imo to have it all accessible through LiveBook.

1 Like

I’d love this as well!

Being able to easily import another Livebook would greatly enhance some of my Livebook workflows.

Even simple use cases like doing Advent of Code in Livebook becomes nicer when you can refer to functions from previous days or create a utility function Livebook that you import from.