Interactive Data Visualization

I have a bunch of data for several different companies. I’m interested in creating an interactive data visualization that I can share with colleagues. Ideally I’d have a drop down to select company (or other interesting thing) and then you’d see tables/graphs etc for that category.
I’m looking for package recommendations to implement something like this. I stumbled upon Makie.jl this morning and it seems promising? I want to make sure I could export whatever I create to some common file format so that I can share with my non technical colleagues. I want to make sure it preserves the interactivity however it’s exported.
Thank you for any recommendations!

1 Like

I would say the approach might depend on the level of interactivity you need. If you just need an interactive legend, using the plotly() backend to Plots.jl could be a good solution. You could share an html file with your colleagues, e.g.:

using Plots
plotly()
plotsplotly = plot(1:100, rand(100), group=repeat([1,2,3,4,5], inner=20))
savefig(plotsplotly, "interactive_legend_plotly.html")

If you need a little more interactivity, I would suggest looking into vega-lite. You can interface to vega-lite through Julia via the package VegaLite.jl. If you have not used vega-lite before, you can start by copying and pasting a vega-lite specificiation (e.g., from the vega-lite website), and save an html file to share, like the following:

using VegaLite
spec = vl"""
{
  "data": {"url": "https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json"},
  "selection": {
    "org": {
      "type": "single",
      "fields": ["Origin"],
      "bind": {"input": "select", "options": [null, "Europe", "Japan", "USA"]}
    }
  },
  "mark": "point",
  "encoding": {
    "x": {"field": "Horsepower", "type": "quantitative"},
    "y": {"field": "Miles_per_Gallon", "type": "quantitative"},
    "color": {
      "condition": {
        "selection": "org",
        "field": "Cylinders", "type": "ordinal"
      },
      "value": ""
    }
  }
}
"""

spec |> save("dropdown_vegalite.html")

There is probably also an option to use Interact.jl, but I have personally not used that package to export a file to share with colleagues. It is likely possible, but I am not aware of the method.

1 Like

Yes, https://github.com/queryverse/VegaLite.jl should be a good choice for this. You can use the syntax that @josephmarturano showed above, but there is much more concise syntax available in the Julia package that is described in the documentation for that package (also look at the examples!).

The information on how to create interactive plots is at Selection Parameters | Vega-Lite.

I think at the end of the day you should then be able to just save the plot as an html file that you can give to your colleagues:

using VegaLite

@vlplot(:point, rand(10), rand(10)) |> save("foo.html")

That html file should be self-contained, and include any interactivity you might have added.

3 Likes

I’m not sure if there are table components in VageLite…

Thank you for the tips, really appreciate it. I am pretty new to Julia and programming generally, so I’m a little confused about the first example Joseph posted. Does julia interact with vegalite in some other language? I guess what I’m saying is I need to ensure I don’t get lost in the learning curve as I’m still picking things up.
As an aside, out of curiousity, did you folks not endorse Makie.jl because you’re not familiar with it? Or perhaps it not the best solution for my particular task?
Thank you!

I would not recommend the type of syntax for VegaLite.jl that @josephmarturano showed above, that is really a fairly advanced/special case interface. I would start with the tutorial in the VegaLite.jl documentation, and then read the other chapters in there and look at the examples in the VegaLite.jl docs to get started.

Makie.jl is great, I’m just more familiar with VegaLite.jl and think that it is a good fit for your scenario, especially because of the standalone export into an HTML file. And, I wrote VegaLite.jl, so I’m kind of biased in recommending it :wink:

Fair enough, that’s a pretty strong endorsement. I’ll take a look.
Thanks again.

Makie is nice for interactive plots with a lot of data, where Javascript / web based solutions struggle. But it doesn’t allow you to export a self-contained version of the interactive plot, you have to run the julia code to get interaction. Self-contained can only work if all your interaction logic is Javascript, so you will never be able to do cool things with julia functions with that approach, just the default things like filtering a data set, calculating means or medians, etc. I think VegaLite and plotly are good for relatively constrained or stereotypical visualization / interaction problems with not too much data. If you have something that requires much more finely tuned interaction, that’s much easier to do in Makie because you have a lot of low-level control.

This is a package that uses a lot of data and more complex interaction with Makie GitHub - JuliaDynamics/InteractiveDynamics.jl: Fast, general-purpose interactive applications for complex systems

2 Likes

Right, I should have explained that better - sorry for the confusion. You can think of vega-lite as its own language, independent of Julia. The Julia wrapper (interface) to vega-lite is called vegalite.jl, but other languages have wrappers too, such as Python’s altair.

What I posted is a method to pass a vega-lite JSON specification that you can copy and paste directly from the vega-lite website. I did not see an example of a drop-down in the vegalite.jl docs, but there are plenty on the vega-lite website, so I thought it would be prudent to show you how to work with the vega-lite specifications with minimal effort. In other words, you could copy/paste a specification, generate an html file, and send it to your colleagues to quickly assess if this approach would meet your need or not.

But if you think vega-lite could work, the following is how you could translate what I posted into vegalite.jl code:

using VegaLite, VegaDatasets
p1 = @vlplot(data=dataset("cars"),
    mark={type="point", tooltip=true, size=75},
    x=:Horsepower,
    y=:Miles_per_Gallon,
    color={condition={selection="org", field="Cylinders", type="ordinal"}, value=""},
    width=800,
    height=600,
    selection={org={type="single", fields=["Origin"], bind={input="select", options=[nothing, "Europe", "Japan", "USA"]}}},
    hover=:Miles_per_Gallon)

save("cars_dropdown.html", p1)

I did add one bonus above, “tooltip=true”, which shows descriptive information on mouse hover. That will add another layer of interactivity on top of the dropdown. I have used this method to send interactive plots to C-suite executives in the past and it was always well received.

Also, you can generate a table using vegalite - here is an example of an interactive table.

2 Likes

Thank you for everybody’s input and specifically for an example containing the drop down. I’ve been playing with VegaLite for a couple hours now and I really like it.
Thank you!