Skip to content

Cancel and Plot Download Buttons#79

Open
Saran-Nag wants to merge 10 commits intoFNLCR-DMAP:devfrom
Saran-Nag:global_buttons
Open

Cancel and Plot Download Buttons#79
Saran-Nag wants to merge 10 commits intoFNLCR-DMAP:devfrom
Saran-Nag:global_buttons

Conversation

@Saran-Nag
Copy link
Copy Markdown
Contributor

Features:

Global cancel buttons using async plot rendering with thread. Generated Plots can have the image download in PNG format.

Overview

Decouples all visualization computations from the Shiny reactive loop by running them in background workers and adding a unified cancellation system across every panel. Button added to Plotly plots to allow users to save the plot on their computer.

Changes

utils/plot_manager.py:

New PlotManager class manages the full worker lifecycle (spawn, poll, cancel, download buttons). Each instance registers in shared['plot_registry'] so app.py has a single control point over all active renders.

app.py:

Cancel_plot() and STOP_BUTTON_MAP replace per-module cancellation logic. Every stop button delegates to one handler; adding cancellation to a new visualization requires no changes here.

Server modules:

All ten files follow a consistent start/poll/render pattern that utilizes the utils/plot_manager.py file. Matplotlib plots run in multiprocessing. Process workers (hard-killable, return PNG bytes); Plotly plots run in threading. Thread workers (Plotly objects can't be pickled across a process boundary).

UI modules:

Every panel gains a stop button (visible only during computation) and PNG/CSV download buttons where applicable (visible only after plot is generated). Matplotlib output slots changed from output_plot to output_image to match the PNG bytes return path.

Testing

The plot download functionality works across all supported visualizations, and the cancel render button successfully allows a new graph to be generated for every plot type once pressed. Cancelation/Downloading of a plot stays distinct to the current tab plot and does not accidentally stop previously built plots or interact with other plots. Docker logs appear stable, with no noticeable bugs or errors.

Notes

Thread cancellation is UI-only due to the global nature of this feature. Plotly threads can’t be killed from outside, so the background thread runs to completion before discarding its result. A Plotly-specific implementation can be included in future updates.

Currently Plot downloading is only in a distinct button for plotly build plots. Generated Plots that uses Shiny Widgets (Boxplots, anno vs anno, scatterplot) have a pre built button so that the plot can be downloaded, however, users are not guided/informed on how to access this feature by the website itself in a direct manner (No text/button indication).

@Saran-Nag Saran-Nag changed the title Global buttons Cancel and Plot Download Buttons Apr 2, 2026
Copy link
Copy Markdown
Contributor

@zhan4329 zhan4329 left a comment

Choose a reason for hiding this comment

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

Hi. Can I ask why we are deleting those comments and docstrings? I think we'd better keep them for better code readability, while docstrings are also required by the CONTRIBUTING.md?

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