Skip to content

Conversation

@vandenman
Copy link
Contributor

@vandenman vandenman commented Sep 24, 2025

Requires jasp-stats/jaspBase#178 and jasp-stats/jaspGraphs#125

Probably best to discuss some of the implementation details in person or via video call or so, but in a nutshell:

  • if possible, show plots as interactive plots by default (for now).
  • switching between the static and interactive version of a plot is possible through the dropdown of a plot.
  • resizing sort of works.

There are quite some rough edges though:

  • For some plots the static version looks fine but the interactive version could use some tweaks (For example, more space between axis title and axis tick labels).
  • The updating of the axes needs to be polished. Right now it can cause flickering when there are many plots.
  • Passing the data now happens through the json directly (as it is json). However, the objects can be very large and make the logs hard if not impossible to read. Perhaps this should be saved as a separate object on disk and loaded in by js to keep the json messages from the desktop/ engine readable.
  • I did not look at html/pdf export. The pdf should just use the static plots. But the html could, in theory, use the standalone feature from plotly. That way most interactivity is retained, although the file size can become quite large.

Nevertheless, I think this draft PR is far enough for:

  1. An initial review.
  2. A starting point for changes to the R analyses related to interactive figures. For example, the analyses in R need to decide what to show in the tooltip that is shown on hover (right now this is just whatever plotly does by default) and also need to check how the variables are named (right now this uses the internal aestethic names, which is what plotly does by default).

Known issues:

  • ggplot2 objects with polar coordinates do not work, see Support for arbitrary coordinate systems plotly/plotly.R#878. This is a problem, because any pie chart (e.g., those in descriptives, but also the BF pizza) is currently implemented in polar coordinates. It's unclear what the best way is to fix this. plotly does support both polar coordinates, and has a separate 'pie' trace type. Both can do exactly what we need, but there is no automatic conversion from ggplot. It's not easy to see from the ggplot object that when we are creating a pie chart, because the ggplot object just contains a bar graph shown in polar coordinates. Possible solutions:
    • Fix the polar coordinate conversion.
    • Inside jaspGraphs, add special plotly code to everything that returns a pie chart, so that instead of calling ggplotly we use the custom plotly code (hacky).

@shun2wang
Copy link
Contributor

Great, this is what I have always wanted to do!👍
A suggestion: It seems that we can streamline some js dependencies. For example, for the jquery library, we can only keep *.min.js instead of .js and .map in the production environment, and only keep those redundant things in the development environment.

@JorisGoosen
Copy link
Contributor

Yes and maybe we can also depend on their respective source repositories as submodules or something, so we can stay up to date easier and with more easily traceable origins

@shun2wang
Copy link
Contributor

Yes and maybe we can also depend on their respective source repositories as submodules or something, so we can stay up to date easier and with more easily traceable origins

Or simply copy them form somewhere while building.

@shun2wang shun2wang self-requested a review September 25, 2025 12:46
@vandenman
Copy link
Contributor Author

It seems that we can streamline some js dependencies.

Sounds like a good idea! For what it's worth, I currently just copied these from a plotly not-standalone export. Basically, in R, export a figure as a not-standalone html which produces an html file and separate includes. The includes I copied over in this PR. Doing this generically is probably possible, although I'm not entirely sure how this will work when in the future people an install a newer or older version of a module, which uses a newer or older version of plotly.

Comment on lines +313 to +333
// Then create new plot
Plotly.newPlot(targetEl, payload.data, payload.layout)
.then(() => {
console.log("Plotly chart rendered successfully");
// Mark the element as having a valid Plotly chart
targetEl._plotlyInitialized = true;
})
.catch((err) => {
console.error("Plotly rendering failed:", err);
targetEl._plotlyInitialized = false;
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JorisGoosen you need to adjust this part if you want to pass the plot differently.

@JorisGoosen
Copy link
Contributor

Ok, ive changed the code to use files as the basis of the plots so the results-json is nice and clean.
I couldnt find out how to switch back to normal plots though?

@vandenman
Copy link
Contributor Author

I'll take a look tomorrow, should be some boolean somewhere that's default should be flipped.

@JorisGoosen
Copy link
Contributor

I found the way to switch and everything seems to work.

@JorisGoosen
Copy link
Contributor

If I export to pdf it seems the interactive plot is exported, is that what we want?
In at least jaspTTests things look a little bit different.

Ill add a basic preference to show/hide interactive plots by default

@JorisGoosen
Copy link
Contributor

JorisGoosen commented Jan 6, 2026

I love how smooth resizing the interactive plots feel btw ❤️
dit: resizing the normal plots behind them seems a bit broken though

Copy link
Contributor

@shun2wang shun2wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend we could just pack https://github.com/plotly/plotly.R/tree/master/inst/htmlwidgets to a htmlwidgets.zip file. and unzip it to cmake build dir and pack it into .qrc while building JASP. To make build clean and simple. Jquery is not necessary cause we already have it as library.

@vandenman
Copy link
Contributor Author

That sounds reasonable, but the plotly version used by R and the js need to be kept in sync somehow, so perhaps not just plotly@master but rather a specific tag or commit. I do remember running into issues with jquery somehow, either they or we (probably we) used an older version which caused some issue. Keeping this working while allowing for different versions of plotly (say when installing an older version of a module) is also something I haven't figured out yet.

@shun2wang
Copy link
Contributor

That sounds reasonable, but the plotly version used by R and the js need to be kept in sync somehow, so perhaps not just plotly@master but rather a specific tag or commit. I do remember running into issues with jquery somehow, either they or we (probably we) used an older version which caused some issue. Keeping this working while allowing for different versions of plotly (say when installing an older version of a module) is also something I haven't figured out yet.

yes, I had tried that but cannot push to this pr then i made that comment above,it was because we already have jquery even that htmlwidgets doesn't include jquery, so plotly.r should never need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants