Skip to content

Commit

Permalink
add flask test
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Zocca committed Jan 7, 2024
1 parent 9f7fd1a commit 5096fc4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
32 changes: 32 additions & 0 deletions plotly_compound_scatter_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import plotly.express as px

def irisScatter1():
"""
:return: px.Figure in JSON
"""
# Load data, make figure.
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length")
trace = next(fig.select_traces())

# Set default point styles.
n = len(trace.x)
color = [trace.marker.color] * n
size = [8] * n
symbol = [trace.marker.symbol] * n

# Modify kth point.
k = 136
color[k] = "red"
size[k] = 15
symbol[k] = "star"

# Update trace.
# trace.marker.color = color
# trace.marker.size = size
# trace.marker.symbol = symbol

# Alternatively, call:
fig.update_traces(marker=dict(color=color, size=size, symbol=symbol))

return fig.to_json()
21 changes: 21 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

from flask import Flask, request, send_file
from markupsafe import Markup, escape

from plotly_compound_scatter_test import irisScatter1

app = Flask(__name__, static_folder='')

@app.get('/')
def index():
return send_file('index.html')

@app.post('/get-data')
def hello():
# name = request.args.get("name", "World")
# return f'Hello, {escape(name)}!'
figJSON = irisScatter1()
return figJSON

if __name__ == "__main__":
app.run(host='0.0.0.0', port=3000, debug=True)

0 comments on commit 5096fc4

Please sign in to comment.