Python Dynamic Power Price Information using Streamlit & Deployed to Windows Server
This video is a follow on from:
Python Future prices, WITS API & My Electricity Bill-https://youtu.be/ZkVWFVpS9wE
Python Remote Trigger from subdomain on Website -https://youtu.be/tJwL5M_wGvM
Python Live Transit Data on Map on Web Subdomain -https://youtu.be/Lt4LdtpVTfg
Objective of project
I wanted to show dynamic chart of electricity prices on a webpage and be able to update the data as required.
I initially wanted to use Plotly Dash but chose Streamlit instead as I’d recently completed a simple share price tutorial and found it easy to use.
Streamlit allows you to use different visualisation libraries and I tried MatPloLib, Altair, Plotly & Bokeh.
In the end I will use the Plotly chart as it meets my needs, especially when using mobile devices.
Deploy to Server Issues
I had a real issue trying to deploy it to a Windows Server.
I couldn’t get the IIS to work as a subdomain for the app so chose to run it on a Task Scheduler trigger and create a Firewall inbound Rule to allow a specific port to be opened so that a HTTP:// to my IP with a specific port could be accessed from remote PC’s and web browsers. This was not the most satisfying solution but as the app is for me personally, its an acceptable solution at this time.
You can deploy your streamlet app to the free streamlet cloud https://streamlit.io/cloud by saving it to a github repository then linking that repository to streamlit for free as long as it’s a public app. If you want it to be private you can create an account to do so.
As I have a VPS Windows server this is not my preferred option, as I want to maintain all my projects on my server, but this is an easy way to have your app running in the cloud.
Using Streamlit
I a very pleased with Streamlit setup and the webpage for the data, it gives me a more personal setup for accessing my data, with a table based on selected pricing criteria as well.
There was a bit of an adjustment to ensure the app worked well on Mobile device and I may have to do some other tweaks to make it look better on a mobile device.
You can get the code here:
NOTE- The API call will not work as the API keys are held in a .env file.
You can path to the CSV file -0_WITAPI_CPK0331_2023-05-26.csv in the same folder so that you can run the streamlit app (chart11.py) , but you will need to load the libraries as shown at the top of the script.
If you want to run the BOKEH library with stremleit at this time you need to do : pip install bokeh==2.4.3 as it doesn’t run with the latest Bokeh v 3 library.
Other references
Articles referred to :
- https://towardsdatascience.com/plotly-dash-vs-streamlit-which-is-the-best-library-for-building-data-dashboard-web-apps-97d7c98b938c
- https://xcorr.net/2021/06/02/dynamic-scientific-visualizations-in-the-browser-for-python-users/
End comment
I was really pleased with the use of Streamlit and its versatility as a python tool, but I was very unimpressed with trying to host it on my windows server.
You would think that a tool like this would make it easy to host across platforms, but that does not seem to be the case with Windows severs.
I am finding python great to use but find trying to deploy the apps difficult. You would think that most of the programs would need to be deployed at sometime so getting the deployment side process right would be a high priority.
Python has lots of avenues like Colab, Jupyter Notebooks, and Django, Flask & other apps and web deployment options to display the data but I do find it a challenge and a bit of a barrier to using python not having programs permanently hosted for continual use, unlike AutoHotKey apps (which really only work on windows so not a fair comparison).
The next app I try to deploy with visualisation I may try using dash instead as I can use flask to deploy it, so can host that on a domain or subdomain on my windows server.