Skip to content
Always-code edited this page Jul 2, 2021 · 5 revisions

Step 2 - Client side application

This section explains 2 python codes required to implement step 2.

dataRetriever.py

  • This python code is written in Visual Studio Code IDE.
  • This code retrieves data from data table in PostgreSQL database.
  • In this code, following steps are implemented:
  1. Import pandas, psycopg2, requests, json python libraries.
  2. Define your Heroku domain name.
  3. Implement 2 functions (sensorData, sensorData200). For more information on these functions, refer 'Functions and Classes' section in this document.

NOTE: sensorData and sensorData200 are function names. You can choose your own function names.

dashboard.py

  • This python code is written in Visual Studio Code IDE.
  • This code constructs a user-interactive dashboard.
  • In this code, following steps are implemented:
  1. Import dash, dash_core_components, dash_html_components, dash_exceptions, dash_dependencies, plotly, matplotlib, numpy, pandas, datetime python libraries.
  2. Import dataRetriever.py file
  3. Define Dash application and a variable to deploy this application on a server.
  4. Define an external stylesheet.
  5. Identify variables most frequently used in the code. Declare these as global variables.
  6. Define application layout using app.layout based on the contents you want in your dashboard. For more information on dash application layouts, visit https://dash.plotly.com/layout
  7. Write a function to obtain current time in seconds. This is required because all parameters in this demo are plotted real-time against time.
  8. Write callback functions. In this demo, 6 callback functions are written. Callback functions are python functions that make dash applications interactive. For more information on the callback functions used in this demo, refer to 'Functions and Classes' section in this document. For more information on dash callback functions, visit https://dash.plotly.com/basic-callbacks

Clone this wiki locally