How do I save an interactive application figure in InteractiveDynamics.jl

Viewed 112

In the documentation for abm_data_exploration in the InteractiveDynamics package, it mentions that the user can save the returned figure. Searching the documentation, I have not been able to deduce what the target filetype ought to be or even what function I should use.

Assume that the figure is defined as such

figure, adf, mdf = abm_data_exploration(
    model, agent_step!, dummystep, parange;
    ac = groupcolor, am = groupmarker, as = 10,
    adata, alabels
) 

How might I save this figure (as an interactive application) to disk?

1 Answers

First, let's talk about the most common use-case. The relevant part of the documentation states:

Calling abm_data_exploration returns: figure, agent_df, model_df. So you can save the figure, but you can also access the collected data (if any).

The returned figure is a Figure from the Makie ecosystem. I believe that what the documentation is hinting at is that after you've finished interacting with the data you can save the final figure as an image or you can process (e.g. plot) the collected data in the dataframes agent_df and model_df. You can save the figure using FileIO.save to whatever format your Makie backend supports. To my knowledge, all backends currently support PNG so as an example:

save("figure.png", figure)

CairoMakie supports saving to EPS, PDF, and SVG in addition to PNG.

Can I save an interactive Makie figure?

The answer could depend on exactly what you want to achieve but it is unlikely that this is something you want to do. When a user interacts with the interface arbitrary Julia code can be executed. The person receiving this application needs Julia and in loading the figure the entire state of Julia (modules, globals, functions) needs to be replicated in that session. Within the same session however, you can close the window and then at a latter point redisplay the figure using display(figure).

Can I create a self-contained relocatable interactive application?

It is possible to compile relocatable apps from Julia code. Not all modules can be included in such relocatable apps, it's not trivial and the resulting binaries are fairly large: PackageCompiler/Relocatable apps.

Related