Closed RaoOfPhysics closed 2 months ago
Use AI instead of hand-crafting prose: https://github.com/explorable-viz/research-strategy/issues/165
@JosephBond This is the new visualisation type we’ll need to add – I think it can be based on similar principles to our existing viz types, but simpler. Initially it won’t be easy to use, as you’ll need to have a specific uniquely named div
for each Text
element, but hopefully there will be some relatively easy things we can do to improve this.
Going to sketch some of my design ideas here over today and tomorrow.
DisplayText
type
List (Either Text Val)
div
's with appropriate ID's, we are going to want a more usable mechanism to provide these thingsDisplayText { }
to be able to use a backquote "`quote"
mechanism like in Lisp, that means invoking the parser on quoted expressions a second time, within the scope of evaluating the DisplayText { }
Whilst in theory this is "simpler" than other visualizations, it's actually not simpler at all. We need some sort of polymorphism in the DisplayText
type, or to at some point get all values that are present, and convert them into strings. It's entirely unclear where to do this because the way we pack/unpack types is really opaque
From my private message to @JosephBond:
OK, so here’s my understanding. The inline chunks on their own are a bit more limited than what we’re trying to do. Most of the text is pre-written with the exception of what is being injected between the inline backticks.
I think these are the right bits of relevant code:
Not exactly sure how it works, but here is some explanation in the R Markdown book: https://bookdown.org/yihui/rmarkdown/r-code.html
Also worth poking at the Knitr book: https://yihui.org/knitr/
@JosephBond I’ve had a very quick scan of the above. We can chat more later today, but perhaps we should conceptually separate “atomic visual elements” (visualisations and fragments of text) from the top-level document structure (which might be a sequence of such things, in a literate programming sort of style). For now, I think we can concentrate on the former. We already have visualisations which are computed from data, so we “just” need to add text computed from data. Then we can insert those text elements into existing HTML documents, just as we currently do with visualisations.
I think your List (Text + Val)
type above is closer to the latter, and would allow the entire content of a web page to be a rendered Fluid value containing both text and graphics (the literate programming “document”). That’s an important perspective to keep in mind, but hopefully we can avoid having to design it right now.
As an example adapted from @RaoOfPhysics‘s report_sphericity
code, suppose the index.html
contained:
<p>Bartlett’s test of sphericity suggests that there is <div id="sig-123">?</div> correlation in ...
We could then (naively) compute a Text
element in Fluid using the following library function:
let sufficient n threshold =
Text(if n >= threshold then "sufficient" else "insufficient")
or even:
let sufficient n threshold =
let s = "sufficient" in Text(if n >= threshold then s else "in" ++ s)
which when plugged into the div
with id sig-123
, would be rendered as (selectable) text to create the final HTML.
@JosephBond Started capturing a few subtasks in the issue body.
@JosephBond Have extracted Examples to a new task, to give us a place to capture some initial ideas..
Text
view typeDrawable
Reflect
develop
)See also:
1040 (library functions)
1045
@rolyp and I have had a few thoughts on this, and I’m attempting here to note some of those in a way that hopefully makes sense.
This was partly inspired by my doctoral thesis (a-ch.in/ty-a#research), where, rather than write numbers by hand, I “injected” the results of calculations straight into the text. For example, the source R Markdown file (
.Rmd
) in question had the following text+code:The output looks like this:
In another instance, I had three statistical tests run thrice to confirm if the dataset in question was suitable for the intended analysis. Similar text would need to explain this each time. Rather than write the sentences and numbers by hand, I wrote a set of functions in R, one for each test, which would output the appropriate text whether the test passed or failed, and would include the calculated numbers corresponding to the test:
Then, wherever I had to include the results, I added the following to the R Markdown file (
.Rmd
) of the analysis chapter:r kmo_benefits
r sphericity_benefits
r alpha_benefits
The output of that particular bit of code appears in the PDF as follows:
(Other instances are on p. 82 and p. 86.)
What we are proposing is the following:
fluid
with the “visualisation” type and parameters inserted there, which will be converted into the calculated figure in the displayed HTML file: `fluid \<some code>`. This will need a bit of fluid code similar to the R packagenombre
, which converts from numbers to text and vice versa: https://nombre.rossellhayes.com/.<mark>
). When selecting specific points in the visualisation, the text should adapt itself based on the underlying data. This can be used for example for dynamic captions, but also for longer paragraphs.