plot$setSize() in .run() works interactively but fails on Export - looking for best practices

Everything related to the development of modules in jamovi
Post Reply
NourEdinDarwish
Posts: 7
Joined: Fri Jan 23, 2026 9:14 pm

plot$setSize() in .run() works interactively but fails on Export - looking for best practices

Post by NourEdinDarwish »

Hi everyone,

I am developing a module that generates plots with dynamic height. I calculate the required height based on user options (number of data rows, groups, etc.), and I am currently calling self$results$plot$setSize() within the .run() function.

I have noticed the following behavior:
  • In the Analysis Window: The plot renders correctly with the dynamic height I calculated.
  • When Saving/Exporting: The saved image reverts to the default dimensions defined in the .r.yaml file, ignoring the size set in .run().
  • Manual Resizing: If I manually resize the plot in the UI and then save, the behavior is inconsistent (sometimes width updates but height doesn't, or it works fine).
I checked some other modules (like linreg) and noticed they often define the size in .init().

My questions are:
  1. Saving Workflow: How exactly does the saving process work? Does it trigger .run() again, or does it only call the render function?
  2. Dimension Priority: How does the system determine the dimensions for the exported image? Why is the size set during .run() seemingly ignored during the save process, even though it appears correct in the window (similar to a manual resize)?
  3. Best Practice: Is .init() the mandatory place to call setSize() for dynamic dimensions? If I depend on calculations that are usually done in .run(), should I move that logic to .init() to ensure exports work correctly?
Thanks for any guidance on the lifecycle of plot dimensions!
User avatar
jonathon
Posts: 2942
Joined: Fri Jan 27, 2017 10:04 am

Re: plot$setSize() in .run() works interactively but fails on Export - looking for best practices

Post by jonathon »

hi,

yes, i would move your $setSize() into .init(). the general rule is to do as much in .init() as you can.

you can also use $setSize2()

https://dev.jamovi.org/api_image-sizing.html

let me know if there are any outstanding issues after that.

> How exactly does the saving process work? Does it trigger .run() again, or does it only call the render function?

calls .init() and the render function ... doesn't call .run()

jonathon
Post Reply