diff options
author | Frederick Muriuki Muriithi | 2021-09-22 07:03:53 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2021-09-22 07:03:53 +0300 |
commit | 920be820e9cefe1dcde86d9a252f098c67a2bb8b (patch) | |
tree | ffa17fce2a2dca25974370cf8a1677fdb3d0b0ac /gn3/api | |
parent | 8442204492a28153e995f3147e06c9758cd3bd28 (diff) | |
download | genenetwork3-920be820e9cefe1dcde86d9a252f098c67a2bb8b.tar.gz |
Return serialized plotly figure
Issue:
https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi
* gn3/api/heatmaps.py: Serialize the figure to JSON
* gn3/heatmaps.py: Return the figure object
Serialize the Plotly figure into JSON, and return that, so that it can be
used on the client to display the image.
Diffstat (limited to 'gn3/api')
-rw-r--r-- | gn3/api/heatmaps.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/gn3/api/heatmaps.py b/gn3/api/heatmaps.py index 43ac580..0493f8a 100644 --- a/gn3/api/heatmaps.py +++ b/gn3/api/heatmaps.py @@ -1,3 +1,4 @@ +import io from flask import jsonify from flask import request from flask import Blueprint @@ -20,4 +21,9 @@ def clustered_heatmaps(): return "{dataset_name}::{trait_name}".format( dataset_name=name_parts[1], trait_name=name_parts[0]) traits_fullnames = [parse_trait_fullname(trait) for trait in traits_names] - return jsonify(build_heatmap(traits_fullnames, conn)), 200 + + with io.StringIO() as io_str: + _filename, figure = build_heatmap(traits_fullnames, conn) + figure.write_json(io_str) + fig_json = io_str.getvalue() + return fig_json, 200 |