Core refactor (HTML download, code cleanup, plot caching) #68
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
HTML Download
Description:
Boxplot and Sankey diagrams can now be downloaded as interactive HTML files
Problems:
Changes:
App.py: Two new shared variables were added to store Sankey and boxplot figures so that the app can reuse the same figure for display and HTML downloading
Server/anno_vs_anno_server.py, server/boxplot_server.py: Now when a Sankey/boxplot Plotly figure is generated, the code saves it to a shared variable, and a download handler is present
Server/data_input_server.py: A helper function was added to sanitize file names and the cleaned file name is stored in a shared variable.
UI/...: Buttons added for downloading
Areas for Improvement:
The UI may be inconsistent now between graphs that can be downloaded as an HTML file and those that cannot
Code cleanup/ if-not hacks and flipper variable
Description:
When originally created, there was a bug in Shiny for Python that crashed the program when a statement like the example below was used:
If x is True: # or "If x” implying the boolean check.
Run Code A
Else:
Run Code B
In order to get around that, the original coder used not statements to flip logic and get around the crashes:
If x is not False: # not False is essentially True
Run Code A
Else:
Run Code B
However, with recent updates to Shiny this issue was fixed, and standard if statements will no longer crash the program. In this PR, we went through the entire code and changed all if-not hacks to follow standard conventions.
The flipper variable was a redundant variable that could be cut out without affecting program performance. Getting rid of it helped declutter the code and improve readability.
Problems:
This change affects multiple files and could have merge conflicts with the main branch
Changes:
Changed all if-not logic to follow normal/standard logic flow. Removed flipper variable.
Caching Dataset to increase efficiency
Description:
Since plot caching would require core refactoring of the codebase and due to the limited time we had at the end of the semester, we decided to go with Dataset caching instead.
We could visibly observe the improvement of loading times for majority of the types of plots on the SPAC Shiny app.
Majority of the logistics are done through the cached_load_data(file_path) function, which first checks if the file is cached, and caches into _data_cache dictionary if not already cached.
The data_input_server module uses the caching functions to load data. It handles: User file uploads (.h5ad and .pickle files), Preloaded dataset selection from dropdowns, Coordinating which data source to use (uploaded vs. preloaded)
Problems:
.pickle file caching is still unstable, compared to .h5ad files
Changes:
data_processing.py and data_input_server.py
Areas for Improvement
Need to quantify the loading times to see exactly how much loading times have improved by