I'm using Flask to generate API and passing the data using rendered template to create charts on html page using py-script.
Please let me know how can I send the rendered html page with all charts over email?
At least if I get an idea to store the rendered html page will also work.
def test():
try:
df = {'C': 20, 'C++': -15, 'Java': 30,
'Python': 35}
cars = ['AUDI', 'BMW', 'FORD', 'TESLA', 'JAGUAR', 'MERCEDES']
point = [23, 17, 35, 29, 12, 41]
#df1 = pd.DataFrame(list(zip(cars, point)), columns=['cars', 'point'])
# showing the prediction results in a UI
return render_template('test.html',data=df,ct=cars,pt=point)
except Exception as e:
print('The Exception message is: ',e)
logging.debug(e)
return 'something is wrong'
Test.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- pandas
- numpy
- matplotlib
</py-env>
</head>
<body>
<py-script>
import matplotlib.pyplot as plt
y = list({{data}}.keys())
x = list({{data}}.values())
plt.barh(y, x, color=['red', 'green', 'blue', 'cyan'])
# setting label of y-axis
plt.ylabel("pen sold")
# setting label of x-axis
plt.xlabel("price")
plt.title("Horizontal bar graph")
plt
</py-script>
</body>
</html>
Regards, Rohan