-
Notifications
You must be signed in to change notification settings - Fork 1
SageWorks Plugins
The Web Interface for the SageWorks Dashboard has the ability to use ‘Plugins’ for web components. These plugins use Dash/Plotly, and allow clients to create custom widgets that are specific to their use cases and needs.
Each plugin class inherits from the SageWorks PluginInterface class and needs to set two attributes and implement two methods. These requirements are set so that each Plugin will conform to the Sageworks infrastructure; if the required attributes and methods aren’t included in the class definition, errors will be raised during tests and at runtime.
# SageWorks Imports
from sageworks.web_components.plugin_interface import PluginInterface, PluginType, PluginInputType
class MyPlugin(PluginInterface):
"""My Awesome Component"""
"""Initialize this Plugin Component Class with required attributes"""
plugin_type = PluginType.MODEL
plugin_input_type = PluginInputType.MODEL_DETAILS
def create_component(self, component_id: str) -> dcc.Graph:
"""Create a Turbo Component without any data.
Args:
component_id (str): The ID of the web component
Returns:
dcc.Graph: My Plugin Component (can also be dash_table.DataTable, dcc.Markdown or html.Div)
"""
< some code >
< return a dcc.Graph with id=component_id>
def generate_component_figure(self, model_details: dict) -> go.Figure:
"""Create a Turbo Figure for the numeric columns in the dataframe.
Args:
model_details (dict): The model details dictionary (see Model.details())
Returns:
go.Figure: A Figure object containing the confusion matrix.
"""
< some code>
< return a go.Figure >
plugin_type = PluginType.MODEL
plugin_input_type = PluginInputType.MODEL_DETAILS
The class variable plugin_type determines what type of plugin the MyPlugin class is. This variable is inspected during plugin loading at runtime in order to load the plugin to the correct artifact page in the Sageworks dashboard. The PluginType class can be DATA_SOURCE, FEATURE_SET, MODEL, or ENDPOINT.
The class variable plugin_input_type is used to control what kind of figure input can be received. Each input type comes from a class method of each artifact object (e.g., DataSource.details(), Endpoint.details(), FeatureSet.details(), or Model.details()) which returns details of that artifact as a dict. The PluginInputType class can be DATA_SOURCE_DETAILS, ENDPOINT_DETAILS, FEATURE_SET_DEATILS, or MODEL_DETAILS.
def create_component(self, component_id: str) -> dcc.Graph:
def generate_component_figure(self, model_details: dict) -> go.Figure:
These methods are required to be implemented, basically create_component
creates the container and generate_component_figure
fills the container. As noted above create_component
can also return a dash_table.DataTable, dcc.Markdown or html.Div.
The example plugin comes with a built in unit test. You can simply run the unit test like so:
python confusion_matrix.py
The test will show the component in your web browser
The test will pull REAL data from the AWS SageWorks System. This is an important part of the development process, unit tests with fake data are great, but getting live data from the system eliminates any ‘mismatch’ in data expectations.
Important Set Up
Since you’ll be invoking the SageWorks API, you’ll need to set yourself up. See the Getting Started Guide for details/
Make sure you have an updated version of SageWorks
pip install --upgrade sageworks
Run the test, which will show the component in your web browser
cd tests/
python confusion_matrix_test.py
This test builds on previous tests, we’ll now run an integration test on a local system that dynamically pulls the plugin into the Dashboard web interface and can be tested as part of the overall system.
git clone [email protected]:SuperCowPowers/sageworks.git
In order for the Dashboard to find the plugins, you must set the SAGEWORKS_PLUGINS ENV
export SAGEWORKS_PLUGINS=/path/to/ideaya-sageworks-plugins/sageworks_plugins
Important
When running the SageWorks Dashboard locally, you do NOT want to use the REDIS_HOST on Ideaya’s AWS account. This will make the interface extremely slow (the cache is a long way away from your laptop). So please run the follow command to make sure your REDIS_HOSTisn’t set
unset REDIS_HOST
Once you’ve got everything set up, you can now Run the Dashboard Locally
cd sageworks/applications/aws_dashboard
python app.py
When running the dashboard locally, if you don’t see your plugin (see example image) then it probably means your SAGEWORKS_PLUGINS ENV var is either not set or set incorrectly. Make sure the ENV var points to the correctly directory that holds the ideaya plugins.
TBD