I have a Python script that ingests GFS model data and plots it using matplotlib. How do I get those exact plots to display on a website? I am currently using PythonAnywhere to build my webpage.
It looks like Python Anywhere has a variety of options for how you can host your website/web application--so the details of how to do this will depend on how you are hosting your site.
One option is Flask, and I'll just point you to Matplotlib's example on embedding Matplotlib within Flask.
Another option is to generate the plots statically somewhere, and then upload them into your static website content. I'm not sure how exactly one one would go about that with Python Anywhere.
Related
I've done some analysis using Pandas on a csv file and have created a number of graphs using matplotlib and plotly.
I'm trying to get these graphs in a html page so my team can see them on a dashboard.
I know it's possible to download the image and embed into html, however, the csv file I performed my analysis on will be constantly updated i.e. I need a way of include the graphs on a html page which auto refreshes.
Is this possible?
I think it would be possible and check pyscrpit
https://pyscript.net/
where you can use python in html
https://github.com/pyscript/pyscript/blob/main/docs/tutorials/getting-started.md
here are some tutorials to get and idea of what I am talking about and to start
Then you can host the html page anywhere you like and they will see when you update it
Voila or Panel to make a dashboard is another way to go. That needs an active Python kernel at this time. (That is as opposed to the pyscript / webassembly route. JupyterLite currently works in WASM and Voila in WASM is in development.) Examining demonstrations available at the Voila Gallery will give you a sense of how it can work. All those example demos are served via MyBinder. And you can use that too, if your code and data can be public. If it cannot be public, you'd need to host a server that only your team can access.
JupyterLite would also be possible if you don't mind your team being able to see the code cells and things that compose your Jupyter notebook stepping through the analysis. That would not require an active Python kernel server-side because it is based on WebAssembly that would run inside the client machine, like PyScript. So all you would need to do was a have a server that can serve static files. That's a lower bar than Voila that would run on the server. How to get started deploying JupyterLite is here.
I would checkout out Dash or Plotly, here you can add generation of the graphs in a callback for isntace. Which would update them when the .csv updates. Good luck!
I'm using retentioneering library with python for analysing complex user behaviors in a website and show it as a graph.
Everything works as expected but now, I would like to provide access to this plots also to other people using a web app built with flask.
This is the result given from retentioneering: retentioneering graph result where you can select various "filters" and drag node to change their location.
I would like to create a web app with this exact graph and filters provided by the library plus, as I said, the drop down.
The problem is that the graph is not just an image but something a user can interact with, so my question is: how can I show it in a dynamic way like here? Is there some specific html object I should use?
Thanks.
Investigating a bit more on how retentioneering works it turns out that the final return value is basically an html with javascript that create the graph.
So using flask displaying this html is really straightforward using the render_template function.
I need to add a real-time chart to my Flask-SocketIO app, for that i found Plotly.
Would it be possible with Plotly to generate a chart which shows both real-time data and past data? When the user opens the page he should be able to see both the data from before the webpage was opened and the new data. How would it be possible to accomplish that with Plotly? Is there an example for it?
For this kind of apps it's highly recommended to feed your real time data to a database and connect your visualization with said database, however I think it is possible to achieve what you want in jupyter notebook with plotly 3 FigureWidget's batch_update. I can't quite get the idea of what you want without some code though.
I'm having trouble getting my mpld3 plot to show up in my Wordpress page. I make my plot, then use mpld3.save_html() to get an html file that contains my figure. However, when I paste this code into my Wordpress page (using the Text editor, not the visual editor) nothing happens. I paste both the script and div tags. I know my javascript is working because I can write alert('Hello'); inside script tags, which works fine. I've also tried installing the "Insert Javascript & CSS" plugin, which also did not work.
Is there some way to embed these graphs into Wordpress, and if not, how does one embed interactive charts in a Wordpress post?
I suspect that the d3.js and mpld3.js were not found, which would explain why you don't see the chart.
There is a d3_url and mpld3_url that you may want to provide and set to the url of a CDN where the files are available for example See https://mpld3.github.io/modules/API.html#mpld3.fig_to_html
Even after setting that properly you may have problems as this is not the recommended way to use javascript within wordpress. You can also try an embed with stricter separation from wordpress: see http://www.datamaplab.com/posts/embedding-javascript-visualization-wordpress/ for reference.
I am using reportlab in python to render a pdf server side.
I really like the look of highcharts graphs. But I am building a pdf server side which needs to include some graphs. The server side graphing (reportlab and matplotlib) do not have nearly as much choices for formatting / design.
Is there a way I can run a client side javascript graphing solution (highcharts) from the server side?
Here is a post with that request and this is what they said:
You feed this Java tool a URL, it fires up its internal WebKit browser, executes the JavaScript code and dumps the rendered page to PDF.
I am looking for resources on how this could be accomplished in python.
I had similar requirements and couldn't find an existing solution so I created a little proof-of-concept solution here.
This implementation works by having the python process create a node subprocess that uses the highchart-export-server node module which in turn spawns a PhantomJS instance to render the chart. A few russian dolls involved there, but it does the job.
Open a web browser on the server.
Point the web browser at a pre-made page that loads highcharts and renders your chart.
Grab the output of the browser.
Send that to a client.
Which of those steps seems confusing?
Note that this will be significantly slower than just using matplotlib, because you need to start up a full web browser just to render a graph. I had a quick look at the highcharts page you linked and I think you could probably reproduce that in matplotlib.