Quarto supports working with multiple programming languages such as R, Python and also ObservableJS. ObservableJS is quite new and might be a bit foreign to R enthusiasts (it was is for me atleast). First let’s talk about what we can create with ObservableJS.
ObservableJS is simply put Javascript with a couple of additions. Inside Quarto we have access to several more components including:
Observable stdlib — Core primitives for DOM manipulation, file handling, importing code, and much more.
Observable Inputs — Standard inputs controls including sliders, drop-downs, tables, check-boxes, etc.
Observable Plot — High level plotting library for exploratory data visualization.
Let’s start with penguins
Let’s start with a simple explanation of how to make a scatterplot with Observable and ObservablePlot.
Why the purrr::transpose()? Well R stores dataframe as a list of columns in a data frame while Javascript (or ObservableJS) expects an Array of objects.
You could do this using Javascript, but who needs that?
Plot.plot({marks: [ Plot.dot(penguins, {x: variable1,// Notice the variable1 defined here is the same one we used in viewofy: variable2,// Same goes herefill:"species",symbol:"species",opacity:0.7,r:4 }) ],symbol: {legend:true},facet: {data: penguins,x:"island"},color: {type:"categorical",scheme:"Set1" },x: {label:"Flipper length (mm)"},y: {label:"Body mass (g)"},grid:true})
ObservableJS allows you to add interactivity with ObservablePlots easily. This normally would require you to have a Shiny server to code completely in R but with a few helpful resources you can create simple plots in ObservableJS with interactivity.
Note
Yes, it is possible to run Shiny inside Quarto using server: shiny and execution contexts. But that requires to run two separate R sessions. Think about the environment, reduce your R sessions.
What about tooltips?
There are three ways ObservablePlot lets you play with pointers.