I am following the schelling.jl tutorial from the Agents.jl package (https://juliadynamics.github.io/Agents.jl/stable/examples/schelling/). Towards the end of the tutorial they create an interactive application. But when I run the script (include("schelling.jl")), I end up with figure instead of an interactive app (cannot click on the run, reset buttons since it appears to be a figure). Any ideas how I get it as an interactive app?
using InteractiveDynamics
figure, adf, mdf = abm_data_exploration(model, agent_step!, dummystep, parange; ac=groupcolor, am=groupmarker, as = 10, adata, alabels)
Note I am using vscode IDE
You need to specify the proper plotting backend, CairoMakie can output static vector graphics but it can't open interactive windows. You can use GLMakie or WGLMakie instead.
Package
Description
GLMakie.jl
GPU-powered, interactive 2D and 3D plotting in standalone GLFW.jl windows.
CairoMakie.jl
Cairo.jl based, non-interactive 2D backend for publication-quality vector graphics.
WGLMakie.jl
WebGL-based interactive 2D and 3D plotting that runs within browsers.
#see Mackie's Backends & Output
Related
I'm in the process of learning R (I'm still a newcomer on SO as well). Being very used to using Visual Studio Code, I decided to choose that over RStudio or RStudio Cloud.
One of the best parts of RStudio was that plots automatically resized/reshaped themselves if we resized the right pane. Moreover, in the tutorials I watched, plots involving map data automatically rendered in the correct aspect ratio (as seen on physical maps).
I replicated the code to make my own plot of the world map. Unfortunately it rendered as a square shape, and resizing the right pane does not affect its shape:
enter image description here
Am I missing any commonly used VSC extensions which can make plots resizeable like in RStudio? (I've installed only the most downloaded extension for R, by Yuki Ueda)
If not, can I modify my code to specify the exact dimensions I need the plot to have?
Thanks in advance!
You can add robust plot viewing options for R in VSCode by installing the httpgd package and then amending your JSON settings.
First, install httpgd via the R console:
install.packages("httpgd")
Then, open your JSON settings in VSCode by opening the Command Palette (either via Ctrl+Shift+P or via View > Command Palette) and then searching for "Preferences: Open Settings (JSON)", where you'll insert the following:
"r.plot.useHttpgd": true
You can add a comma after 'true' if needed (i.e. if there are other lines below that in your JSON settings).
Following that, restart VSCode and launch the R terminal inside it, and plot something using either ggplot2 or base R graphics:
plot(mtcars$mgp, mtcars$wt)
A plot viewer should then pop up in VSCode. You can either manually resize the window there, zoom in or out, or, my preference (particularly if I'm cycling through a series of already-plotted graphs), open it in an external browser where it'll automatically adjust to however you resize the window. After that, you can save or copy the image as needed.
You can specify the dimensions when you save the file. I usually use (approximately) the golden ratio:
ggsave("./earth.png", width = 16, height = 10)
The ggsave function reference explains how you can change units - options are c("in", "cm", "mm", "px").
I would like to embed a Bokeh figure inside a Dash app, but I can't figure out how to render the Bokeh JSON in Dash.
The simplest solution would be to use Bokeh or Dash on its own. All our other apps at work use Dash (so Bokeh alone is undesirable), however, Dash/Plotly cannot generate the required figure (a raster image overlaid on a tiled map).
There is an old post on the Plotly community forum asking the same question, and the proposed solution was to use the dash-alternative-viz package to embed the Bokeh figure. Unfortunately, the package doesn't render Bokeh plots, even when copying the example usage.py script. This has been raised as an issue on the repo, but the developers have yet to respond.
Bokeh can supply JSON data that BokehJS can use to render a standalone figure (bokeh.embed.json_item()), and the docs give an example of how to serve a Bokeh figure to a Flask app:
#app.route('/plot')
def plot():
p = make_plot('petal_width', 'petal_length')
return json.dumps(json_item(p, "myplot"))
How can I do something similar in Dash?
dash-alternative-viz is a proof-of-concept Dash component library that provides Dash interfaces to other visualization libraries like Bokeh. Check out their github page to read more and get started:
https://github.com/plotly/dash-alternative-viz-demo
I'm plotting F# functions in a Jupyter Notebook on a .NET Interactive Kernel like this:
Plotting F# function in Jupyter
I want to make this graph interactive so variables (and therefore the line of the graph) can be manipulated live. Is it possible to add a slider UI control with F#, like it can be done in Python with ipywidgets?
Problem: ploting images is usually long in R (user-side), even when using raster.
Possible trail: With images as objects of class magick-image, one can use RStudio's viewer as proposed/implemented in the magick's package vignette.
There is an open issue on magick's github repos dedicated to this particular magick+ shiny combination and detailing the rationale.
What I have found: Rstudio's support indicates how to display a shiny app within the viewer but I'm looking for the opposite: display an efficient viewer within a shiny app.
Question: is there a generic way to integrate RStudio's viewer (or equivalent) within a shiny app?
(By the way) question: can we retrieve clicked coordinates and other events from the viewer (or equivalent)?
I have produced a plot using the ggvis package in R. The plot is interactive which can be changed by moving around the slider. However when I save it, it is just a picture of current status without sliders.
I have seen people posting these interactive plots on the website, so I think there should be a way to save it first. How can I do this?
From the Rstudio page for ggvis:
Note: If you’re viewing the HTML version of this document generated with knitr, the examples will have their interactive features disabled. You’ll need to run the code in R to see and use the interactive controls.
From this and the whole page I gather that sharing the interactive graphics can be done using Shiny Apps and/or R Markdown documents. To deploy either of those to people who do not have R installed you need to a) use Shiny Apps IO; or b) install Shiny Server, which has a free version with very basic administration capabilities, and a paid version for confidential information in corporate environment (which I'm only mentioning in case you are not allowed to share your data).
Either way, read through the Shiny Tutorial, the
R Markdown Tutorial, and the combination.