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

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?

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

Interactive Document (takes input gives output) in Rpubs

Is it possible to publish an RMarkdown file to Rpubs that takes input and gives out put from the Rpubs site? I want to create a simple calculator related to my job that takes a few inputs and gives an output and, if possible, publish to Rpubs for people to view and use.
SHINY: I know this is what shiny is for, creating interactive apps, but I dont know it very well or how to implement an app I create for multiple people to use, or how to imbed the link to the app, and so on. Just trying to see if this is possible in things I already know how to use
RPubs is for HTML documents that don't require R calculations on the backend. In some instances, there can be some degree of interactivity e.g., brushing and linking plots, filtering data and having the filter propagate to a plot. These happen through the crosstalk package. However, it sounds like you need a shiny app that can take inputs and have R do some calculation of those on the back end. You could host your app on shinyapps.io
It's also possible, depending on how complicated the calculations are, that the entire app could be written in native javascript, which wouldn't require a server-side computation, so could be hosted on any website.

auto documentation system for R shiny

I ask for any advice how to do documentaion / auto-documentation for larger shiny applications.
R packages have roxygen2, but are there any equivalents of auto-documentation for shiny server and ui code?
I'm working on a developing project of +15k lines of code and we push as much as possible to packages with roxygen2 docs, however all of the observes and reacts in central server script and its subscripts are not auto-documented. I also use git of course.
I have tried to tag every observe, reactive, module etc in source code with a unique ID and draw a diagram manually with corresponding IDs. The diagram describe what type of sub-element and topic. Later I would add all triggers etc. This process is very manual though. Maybe I could use "the reactive log" https://shiny.rstudio.com/articles/debugging.html to autogenerate such documentation?
...update 1: I have tried ShinyTester which reads through source code and try to predict a network of sub-element interactions. It did not handle sourcing of external files, but with a little debug I manage to get the below diagram. Unfortunately, only 5% of elements and interactions were discovered hereby. Maybe ShinyTester could need some contributions. :

Redirect all plot output to specific file

I want to automatically redirect all plotting to a file (reason: see below). Is there a non-hacky way of accomplishing that?
Lacking that, I’m actually not afraid of overriding the built-in functions, I’m that desperate. The easiest way I can think of is to hook into the fundamental plot-window creation function and calling pdf(…) and then hooking into the plot-finalising function and calling dev.off() there.
But what are these functions? Through debugging I’ve tentatively identified dev.hold and dev.flush – but is this actually true universally? Can I hook into those functions? I cannot override them with R.utils’ reassignInNamespace because they are locked, and just putting same-name functions into the global namespace doesn’t work (they’re ignored by plot).
So, why would I want to do something so horrible?
Because I’m working on a remote server and despite my best attempts, and long debugging sessions with our systems support, I cannot get X11 forwarding to work reliably. Not being able to preview a plot is making my workflow horribly inefficient. I’ve given up on trying to get X11 to work so now I’m creating PDFs in my public_html folder and just refresh the browser.
This works quite well – except that it‘s really annoying and quite time-consuming to always have to surround your plotting function calls with pdf(…) … dev.off(), especially in interactive sessions where you want to quickly create a plot while in a meeting with collaborators. In fact, it’s really annoying and they (understandably) haven’t got the patience for that.
For now I’m helping myself with the following function definition:
preview <- function (.expr, ...) {
on.exit(dev.off())
pdf(PREVIEW_FILE_NAME, ...)
eval(substitute(.expr))
}
Which is used like this:
preview(plot(1:100, rnorm(100) * 1:100))
That works a-ok. But this workflow is a real bottleneck in meetings, and I’d like to get rid of the preview call to streamline it as much as possible.
Any chance at all?
If you set options(device=FUN) then the graphics device function FUN becomes the new default graphics device that will be opened when a plot is created and device is not already opened.
So, one option would be to write a function that calls pdf or png or other graphics device with the filename and options that you want (probably onefile=FALSE in pdf), then set this function as the default in the options. You may need to use one of dev.off, plot.new, or frame to finalize the current plot (R does not finalize until you close the device or go to a new plot in case you want to add anything to the current plot).
If you will never add to a plot then you could use addTaskCallback to call dev.off automatically for you. There may be other hooks that you could use to finalize as well.

Large Graph Visualization Library

I need to visualize a very large graph ( > 1 million ) in a website, the library should to receive a JSON and generate a png.
I've already tried graphviz with spfd but the waiting is too long, the user will not be able to interact with a GUI so Cytoscape or Gephi are not an option.
Another option could be maybe exporting a .dot to web, but I don't know how efficient this would be.
http://www.gnuplot.info/ and http://dygraphs.com/ are two of my favorite charting libraries for the web. Plotting a million data points I would probably use gnuplot. I would look at caching generated images as much as possible, perhaps even generating them in a batch rather than at the time of the request. I think you will run into performance issues trying to pass the data in via JSON and attempting to render the graph client side.

Does anyone know how to create a interactive graphs using flare or other visualisation classes?

Does anyone know of software or flex/flash/as3 source or visualisation software that could be used to make interactive graphs, where the user would enter a query that would pull data from a MySQL database and the user would build a sunburst or icicle graph by dragging and dropping items into a tree-like structure and they would be able to view the graph? i have attempted to use flare but my programming skills are pretty bad. So far from what i gather, flare only allows the graphing of defined datasets rather than allowing a user to modify the dataset and thus creating a new dataset.
Help?
This is far too big for the scope of a single question. You're going to need to write at least a few different pieces.
1.) Access to the database and a way to view datasets
2.) Control handlers to drag and drop datasets onto your chart object
3.) A chart object that can handle receiving dropped dataset items and render itself accordingly.
There are lots of good charting frameworks out there including Flare, Axiis, Flex charting, Fusion Charts, iLog Elixir. I'm not sure what you're trying to do but any one of those should be able to serve as your charting piece.
We worked on a project that used Flare and Flex. We had to provide the data to Flare in an XML format called GraphML, so we had code to convert the data into the required format in our C# backend, and then we passed it to Flex. There were naff all tutorials for it though, so took some time to figure it out.
There is a properly cool graphing tool (although its commercial) called Kapit. Check out their Diagrammer and Visualizer demos. It could be the case that its worth the spend.
But I agree with Mr Owen, theres some mad scope in that question:)

Resources