nanohub-dashboards
Python client library for interacting with the nanoHUB Dashboard API. Load, manipulate, visualize, and save dashboards programmatically.
Installation
Install from PyPI:
pip install nanohub-dashboards
Then import in your code:
import nanohubremote as nr
from nanohubdashboard import Dashboard
Note: The package is published as nanohub-dashboards on PyPI but imported as nanohubdashboard (no hyphen).
Features
- Load existing dashboards from nanoHUB
- Manipulate plot configurations (types, properties, etc.)
- Add new plots and graphs to dashboards
- Preview dashboards locally before saving
- Save changes back to nanoHUB
- Export dashboards to standalone HTML files
- Render individual plots and graphs locally without API access
- Full support for Plotly-based visualizations
- NEW (0.2.1):
connect()helper — authenticate fromNANOHUB_TOKENenv var or a.envfile - NEW (0.2.1): Report generation — standalone HTML or Markdown reports with figures, summary statistics, and data tables
- NEW (0.2.1): CSV export of dashboard query results
- NEW (0.2.1): Data source catalog — search and describe data sources, with example queries mined from dashboards
- NEW (0.2.1): Lossless raw create/update (
create_dashboard_raw/update_dashboard_raw) for partial updates that keep%PLACEHOLDERplot templates intact
Quick Start
Connecting
The simplest way to get a client is connect(), which reads your token from
the NANOHUB_TOKEN environment variable or a .env file in the working
directory (NANOHUB_URL selects the instance, default https://nanohub.org):
from nanohubdashboard import connect
client = connect() # env / .env
client = connect(token="...", url="https://dev.nanohub.org")
client.list_dashboards({"limit": 10})
client.query_datasource(12, "SELECT * FROM tool_usage LIMIT 5")
client.visualize(19, output_file="dashboard.html", open_browser=False)
Generating Reports
client.generate_report(19, "report.html") # interactive HTML
client.generate_report(19, "report.md", format="markdown") # text summary
client.export_dashboard_data(19, "data/") # CSV per query
Basic Usage
import nanohubremote as nr
from nanohubdashboard import Dashboard
# Create authenticated session
auth_data = {
"grant_type": "personal_token",
"token": "your_token_here"
}
session = nr.Session(auth_data, url="https://nanohub.org/api")
# Load a dashboard
dashboard = Dashboard(session)
dashboard.load(dashboard_id=8)
# View dashboard information
dashboard.print_graphs()
# Manipulate plots
dashboard.swap_all_bar_scatter()
# Visualize locally
dashboard.visualize(
output_file="my_dashboard.html",
open_browser=True
)
# Save changes back to nanoHUB
dashboard.save()
Preview Before Saving
Preview how your dashboard will look on the server without saving changes:
# Preview the dashboard configuration
dashboard.preview(open_browser=True)
Working with Individual Graphs
# Get a specific graph
graph = dashboard.get_graph(0)
# Access plots in the graph
for plot in graph.plots:
print(f"Plot type: {plot.type}")
# Modify plot properties
if plot.type == 'bar':
plot.type = 'scatter'
plot.mode = 'markers'
Adding New Plots
from nanohubdashboard import Graph, Plot
# Create a new plot
plot_config = {
'type': 'scatter',
'mode': 'lines',
'x': '%X_DATA',
'y': '%Y_DATA',
'name': 'My Plot'
}
plot = Plot(plot_config, index=0)
# Create a graph with the plot
graph = Graph(
query='MY_QUERY',
zone='main',
priority=1
)
graph.plots = [plot]
# Add to dashboard
dashboard.add_graph(graph)
Rendering Single Plots Locally (No API Required)
NEW! You can now create and render standalone plots without connecting to the API:
from nanohubdashboard.plot import Plot
from nanohubdashboard.graph import Graph
# Simple plot with direct data
plot = Plot({
'type': 'scatter',
'mode': 'markers',
'x': [1, 2, 3, 4, 5],
'y': [2, 4, 6, 8, 10],
'name': 'My Data'
}, index=0)
plot.visualize(output_file='my_plot.html')
# Or use placeholders for dynamic data
plot = Plot({
'type': 'scatter',
'x': '%X_DATA',
'y': '%Y_DATA',
'name': '%SERIES_NAME'
}, index=0)
data = {
'x_data': [1, 2, 3],
'y_data': [4, 5, 6],
'series_name': 'Temperature'
}
plot.visualize(data=data, output_file='dynamic_plot.html')
# Multiple series in one graph
graph = Graph(index=0)
graph.add_plot({'type': 'scatter', 'x': [1,2,3], 'y': [1,4,9], 'name': 'Series 1'})
graph.add_plot({'type': 'scatter', 'x': [1,2,3], 'y': [1,2,3], 'name': 'Series 2'})
graph.visualize(output_file='multi_series.html')
See SINGLE_PLOT_QUICKSTART.md for more details.
Core Components
Dashboard
The main class for working with dashboards:
load(dashboard_id): Load a dashboard from the APIsave(): Save changes back to the servervisualize(output_file, open_browser): Generate local HTML visualizationpreview(output_file, open_browser): Preview server-rendered dashboardget_graph(index): Get a specific graph by indexadd_graph(graph): Add a new graph to the dashboardlist_graphs(): List all graphs in the dashboardprint_graphs(): Print a summary of all graphs
Graph
Represents a single graph/visualization in the dashboard:
plots: List of Plot objects in this graphquery: SQL query name that provides the datazone: Layout zone where the graph appearspriority: Display order prioritylayout_config: Plotly layout configurationhtml: Custom HTML content (for non-Plotly graphs)visualize(data, layout, output_file, open_browser): NEW - Render graph as standalone HTMLadd_plot(plot_config): Add a new plot to this graph
Plot
Represents a single plot trace within a graph:
type: Plot type (e.g., 'scatter', 'bar', 'pie')mode: Plot mode for scatter plots (e.g., 'lines', 'markers')config: Full Plotly configuration dictionaryvisualize(data, layout, output_file, open_browser): NEW - Render plot as standalone HTML- Direct property access (e.g.,
plot.x,plot.y,plot.name)
DashboardClient
Low-level API client for direct API access:
list_dashboards(filters): List accessible dashboardsget_dashboard(dashboard_id): Get dashboard configurationcreate_dashboard(dashboard_config): Create a new dashboardcreate_dashboard_raw(data): Create from a raw dict (placeholders kept verbatim)update_dashboard(dashboard_id, dashboard_config): Update dashboardupdate_dashboard_raw(dashboard_id, data): Partial update from a raw dictdelete_dashboard(dashboard_id): Delete a dashboardlist_datasources(search, group_id): List readable data sourcesdescribe_datasource(id, counts, examples): Schema, SQL functions and example queriessearch_datasources(query): Find tables, columns and example queries across data sourceslist_templates()/get_template(id): Layout templatesquery_datasource(id, sql, format): Run a SELECT against a datasourceupload_datasource(...)/download_datasource(...): Move SQLite filespreview_dashboard(...): Server-side preview renderingvisualize(...): Generate local visualizationgenerate_report(id, output, format): HTML/Markdown reportexport_dashboard_data(id, dir): CSV export of query results
Authentication
The library uses nanohub-remote for authentication. You need a nanoHUB personal access token.
Getting Your API Token
- Visit https://nanohub.org/developer/api/docs
- Navigate to Settings → Developer → Personal Access Tokens
- Generate a new personal access token
- Copy the token for use in your code
Using the Token
auth_data = {
"grant_type": "personal_token",
"token": "your_token_here"
}
# Production environment
session = nr.Session(auth_data, url="https://nanohub.org/api")
# Development environment (for testing)
# Use this to safely experiment without affecting production data
session = nr.Session(auth_data, url="https://dev.nanohub.org/api")
Note: When testing or developing features, you can use the development environment (url="https://dev.nanohub.org/api") to safely experiment without affecting production dashboards.
Examples
See the examples directory for complete working examples:
- demo_simple_api.py: Basic dashboard manipulation
- demo_base.py: Complete workflow including save and preview
- demo_add_plots.py: Adding new graphs and plots
- demo_single_plot_rendering.py: NEW - Standalone plot rendering (6 examples)
- demo_single_plot_rendering.ipynb: NEW - Jupyter notebook version
Requirements
- Python >= 3.6
- requests
- plotly
- pandas
- nanohub-remote
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues and questions:
- GitHub Issues: Report issues
- nanoHUB Support: Contact support
Metadata
Release files for nanohub-dashboards 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nanohub_dashboards-0.2.1.tar.gz | 70.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nanohub_dashboards-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 118.6 kB
Release files / nanohub_dashboards-0.2.1.tar.gz
| Download URL | nanohub_dashboards-0.2.1.tar.gz |
|---|---|
| Size | 70.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3aa09059551cdd7d2296d590c8049c86c930be657ed92486e27a027bd428470f
|
|
BLAKE2b-256 checksum How to use checksums |
eacf83f6b89031ff82e186b4686544347d5a492b1fd0c9c6e620dc55fd1e36f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Release files / nanohub_dashboards-0.2.1-py3-none-any.whl
| Download URL | nanohub_dashboards-0.2.1-py3-none-any.whl |
|---|---|
| Size | 48.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c8e40dd619ecba9e01fe6f6e5b6c8e3feba7651c1e6ae5f8c763118ff55f121
|
|
BLAKE2b-256 checksum How to use checksums |
09f2b2626ffab106daec36dec18d8b711a46f1064c3d152c6897a23bafc60639
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|