staticdash 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -128,7 +128,7 @@ tr:nth-child(even) {
128
128
  background-color: #f2f2f2;
129
129
  }
130
130
 
131
- tr:hover {
131
+ tbody tr:hover {
132
132
  background-color: #e8f0fe;
133
133
  }
134
134
 
@@ -151,4 +151,27 @@ tr:hover {
151
151
 
152
152
  .download-button:hover {
153
153
  background-color: #547a9f;
154
+ }
155
+
156
+ table.sortable th {
157
+ cursor: pointer;
158
+ position: relative;
159
+ padding-right: 1.5em;
160
+ user-select: none;
161
+ }
162
+
163
+ table.sortable th::after {
164
+ content: "";
165
+ position: absolute;
166
+ right: 0.5em;
167
+ font-size: 0.9em;
168
+ pointer-events: none;
169
+ }
170
+
171
+ table.sortable th.sorted-asc::after {
172
+ content: "\25B2";
173
+ }
174
+
175
+ table.sortable th.sorted-desc::after {
176
+ content: "\25BC";
154
177
  }
@@ -40,4 +40,55 @@ document.addEventListener("DOMContentLoaded", () => {
40
40
  if (sections.length > 0) {
41
41
  showPage(sections[0].id);
42
42
  }
43
+
44
+ // Table sorting for tables with class "sortable"
45
+ document.querySelectorAll("table.sortable").forEach(function (table) {
46
+ const headers = table.querySelectorAll("thead th");
47
+ let originalRows = null;
48
+
49
+ headers.forEach(function (th, colIdx) {
50
+ th.addEventListener("click", function () {
51
+ if (!originalRows) {
52
+ const tbody = table.querySelector("tbody");
53
+ originalRows = Array.from(tbody.querySelectorAll("tr"));
54
+ }
55
+
56
+ // Cycle: none -> asc -> desc -> none
57
+ let state = th.dataset.sorted;
58
+ let nextState = state === "asc" ? "desc" : state === "desc" ? "none" : "asc";
59
+
60
+ headers.forEach(h => {
61
+ h.classList.remove("sorted-asc", "sorted-desc");
62
+ h.dataset.sorted = "none";
63
+ });
64
+
65
+ th.dataset.sorted = nextState;
66
+ if (nextState === "asc") th.classList.add("sorted-asc");
67
+ if (nextState === "desc") th.classList.add("sorted-desc");
68
+
69
+ const tbody = table.querySelector("tbody");
70
+ if (nextState === "none") {
71
+ originalRows.forEach(row => tbody.appendChild(row));
72
+ return;
73
+ }
74
+
75
+ const rows = Array.from(tbody.querySelectorAll("tr"));
76
+ rows.sort(function (a, b) {
77
+ const aText = a.children[colIdx].textContent.trim();
78
+ const bText = b.children[colIdx].textContent.trim();
79
+ // Numeric sort if both are numbers
80
+ const aNum = parseFloat(aText);
81
+ const bNum = parseFloat(bText);
82
+ if (!isNaN(aNum) && !isNaN(bNum)) {
83
+ return nextState === "asc" ? aNum - bNum : bNum - aNum;
84
+ }
85
+ // String sort (works for ISO dates)
86
+ return nextState === "asc"
87
+ ? aText.localeCompare(bText)
88
+ : bText.localeCompare(aText);
89
+ });
90
+ rows.forEach(row => tbody.appendChild(row));
91
+ });
92
+ });
93
+ });
43
94
  });
staticdash/dashboard.py CHANGED
@@ -4,7 +4,7 @@ import uuid
4
4
  import pandas as pd
5
5
  import plotly.graph_objects as go
6
6
  from dominate import document
7
- from dominate.tags import div, h1, h2, p, a, script, link, table, thead, tr, th, tbody, td, span
7
+ from dominate.tags import div, h1, h2, h3, h4, p, a, script, link, table, thead, tr, th, tbody, td, span
8
8
  from dominate.util import raw as raw_util
9
9
 
10
10
  class Page:
@@ -12,6 +12,12 @@ class Page:
12
12
  self.slug = slug
13
13
  self.title = title
14
14
  self.elements = []
15
+ self.add_header(title, level=1) # Add page title as level 1 header
16
+
17
+ def add_header(self, text, level=1):
18
+ if level not in (1, 2, 3, 4):
19
+ raise ValueError("Header level must be 1, 2, 3, or 4")
20
+ self.elements.append(("header", (text, level)))
15
21
 
16
22
  def add_text(self, text):
17
23
  self.elements.append(("text", text))
@@ -20,10 +26,13 @@ class Page:
20
26
  html = raw_util(plot.to_html(full_html=False, include_plotlyjs='cdn', config={'responsive': True}))
21
27
  self.elements.append(("plot", html))
22
28
 
23
- def add_table(self, df, table_id=None):
29
+ def add_table(self, df, table_id=None, sortable=True):
24
30
  if table_id is None:
25
31
  table_id = f"table-{len(self.elements)}"
26
- html = df.to_html(classes="table-hover table-striped", index=False, border=0, table_id=table_id)
32
+ classes = "table-hover table-striped"
33
+ if sortable:
34
+ classes += " sortable"
35
+ html = df.to_html(classes=classes, index=False, border=0, table_id=table_id, escape=False)
27
36
  self.elements.append(("table", (html, table_id)))
28
37
 
29
38
  def add_download(self, file_path, label=None):
@@ -43,9 +52,18 @@ class Page:
43
52
 
44
53
  def render(self, index):
45
54
  section = div(id=f"page-{index}", cls="page-section")
46
- section += h1(self.title)
47
55
  for kind, content in self.elements:
48
- if kind == "text":
56
+ if kind == "header":
57
+ text, level = content
58
+ if level == 1:
59
+ section += h1(text)
60
+ elif level == 2:
61
+ section += h2(text)
62
+ elif level == 3:
63
+ section += h3(text)
64
+ elif level == 4:
65
+ section += h4(text)
66
+ elif kind == "text":
49
67
  section += p(content)
50
68
  elif kind == "plot":
51
69
  section += div(content, cls="plot-container")
@@ -81,9 +99,19 @@ class Dashboard:
81
99
 
82
100
  with doc:
83
101
  with div(cls="page-section", id=f"page-{page.slug}"):
84
- h1(page.title)
102
+ # Remove h1(page.title) here, since it's already a header element
85
103
  for kind, content in page.elements:
86
- if kind == "text":
104
+ if kind == "header":
105
+ text, level = content
106
+ if level == 1:
107
+ h1(text)
108
+ elif level == 2:
109
+ h2(text)
110
+ elif level == 3:
111
+ h3(text)
112
+ elif level == 4:
113
+ h4(text)
114
+ elif kind == "text":
87
115
  p(content)
88
116
  elif kind == "plot":
89
117
  div(content, cls="plot-container")
@@ -110,9 +138,19 @@ class Dashboard:
110
138
  with div(id="content"):
111
139
  for page in self.pages:
112
140
  with div(id=f"page-{page.slug}", cls="page-section", style="display:none;"):
113
- h2(page.title)
141
+ # Remove h2(page.title) here, since it's already a header element
114
142
  for kind, content in page.elements:
115
- if kind == "text":
143
+ if kind == "header":
144
+ text, level = content
145
+ if level == 1:
146
+ h1(text)
147
+ elif level == 2:
148
+ h2(text)
149
+ elif level == 3:
150
+ h3(text)
151
+ elif level == 4:
152
+ h4(text)
153
+ elif kind == "text":
116
154
  p(content)
117
155
  elif kind == "plot":
118
156
  div(content, cls="plot-container")
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.4
2
+ Name: staticdash
3
+ Version: 0.2.2
4
+ Summary: A lightweight static HTML dashboard generator with Plotly and pandas support.
5
+ Author-email: Brian Day <brian.day1@gmail.com>
6
+ License: CC0-1.0
7
+ Project-URL: Homepage, https://github.com/briday1/staticdash
8
+ Project-URL: Repository, https://github.com/briday1/staticdash
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: plotly
12
+ Requires-Dist: pandas
13
+ Requires-Dist: dominate
14
+
15
+ # staticdash
16
+
17
+ staticdash is a lightweight Python module for creating static, multi-page HTML dashboards. It supports:
18
+
19
+ - Plotly plots (interactive, responsive)
20
+ - Pandas DataFrames as sortable tables
21
+ - Text and headers (Markdown-like)
22
+ - File download buttons
23
+ - Multi-page navigation with sidebar
24
+ - Custom CSS and JavaScript
25
+ - Easy extension for new content types
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ git clone https://github.com/briday1/staticdash.git
31
+ cd staticdash
32
+ pip install .
33
+ ```
34
+
35
+ ## Features
36
+
37
+ - **Add Plotly figures:** `page.add(fig)`
38
+ - **Add tables:** `page.add(df)` (sortable by default)
39
+ - **Add text or headers:** `page.add("Some text")`, `page.add_header("Title", level=2)`
40
+ - **Add download buttons:** `page.add_download("path/to/file", "Label")`
41
+ - **Multi-page:** Create multiple `Page` objects and add them to your `Dashboard`
42
+ - **Custom styling:** Edit `assets/css/style.css` for your own look
43
+
44
+ ## Options
45
+
46
+ - **Sidebar navigation:** Fixed, with active highlighting
47
+ - **Responsive layout:** Works on desktop and mobile
48
+ - **Export:** Outputs a static HTML dashboard (no server needed)
49
+ - **Per-page HTML:** Also generates individual HTML files for each page
50
+
51
+ ## Live Demo
52
+
53
+ [View the latest demo dashboard](https://briday1.github.io/staticdash/)
54
+
55
+ ---
56
+
57
+ For a full example, see [`demo.py`](./demo.py) in this repository.
@@ -0,0 +1,8 @@
1
+ staticdash/__init__.py,sha256=KqViaDkiQnhBI8-j3hr14umLDmPgddvdB_G1nJeC5Xs,38
2
+ staticdash/dashboard.py,sha256=trPzco0AZw4IAwZzgY__RsOjwg4UrD7etB-4Da1kHE0,7515
3
+ staticdash/assets/css/style.css,sha256=kL6FAGxIwYrfNoo4oCzC-ygHmyOZDEjhjixpY0YGpss,2649
4
+ staticdash/assets/js/script.js,sha256=SMOyh7_E_BlvLYMEwYlvCnV7-GnMR-x8PtEiFbIIAsw,3089
5
+ staticdash-0.2.2.dist-info/METADATA,sha256=VDgodqPfaNsvqb-H8gqWWpixRKZie42xF3xG7jlz7rA,1776
6
+ staticdash-0.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ staticdash-0.2.2.dist-info/top_level.txt,sha256=3MzZU6SptkUkjcHV1cvPji0H4aRzPphLHnpStgGEcxM,11
8
+ staticdash-0.2.2.dist-info/RECORD,,
@@ -1,89 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: staticdash
3
- Version: 0.2.0
4
- Summary: A lightweight static HTML dashboard generator with Plotly and pandas support.
5
- Author-email: Brian Day <brian.day1@gmail.com>
6
- License: CC0-1.0
7
- Project-URL: Homepage, https://github.com/briday1/staticdash
8
- Project-URL: Repository, https://github.com/briday1/staticdash
9
- Requires-Python: >=3.8
10
- Description-Content-Type: text/markdown
11
- Requires-Dist: plotly
12
- Requires-Dist: pandas
13
- Requires-Dist: dominate
14
-
15
- # staticdash
16
-
17
- staticdash is a lightweight Python module for creating static, multi-page HTML dashboards. It supports Plotly plots, tables, and text content, with a fixed sidebar for navigation.
18
-
19
- ## Installation
20
-
21
- Clone the repository and install it in editable mode:
22
-
23
- ```bash
24
- git clone https://github.com/briday1/staticdash.git
25
- cd staticdash
26
- pip install .
27
- ```
28
-
29
- ## Usage
30
-
31
- Create a Python script like this:
32
-
33
- ```python
34
- from staticdash.dashboard import Dashboard, Page
35
- import plotly.express as px
36
- import pandas as pd
37
- import numpy as np
38
-
39
- # Create sample data
40
- df = pd.DataFrame({
41
- "Category": ["A", "B", "C", "D"],
42
- "Value": [10, 20, 30, 40]
43
- })
44
-
45
- df2 = pd.DataFrame({
46
- "Time": pd.date_range("2024-01-01", periods=10, freq="D"),
47
- "Signal": np.random.randn(10).cumsum()
48
- })
49
-
50
- fig1 = px.bar(df, x="Category", y="Value", title="Bar Chart Example")
51
- fig2 = px.line(df2, x="Time", y="Signal", title="Signal over Time")
52
-
53
- # Build dashboard
54
- dashboard = Dashboard(title="StaticDash Demo")
55
-
56
- # Page 1: Overview
57
- page1 = Page("overview", "Overview")
58
- page1.add("Welcome to the StaticDash demo. Below is a bar chart and a table.")
59
- page1.add(fig1)
60
- page1.add(df)
61
-
62
- # Page 2: Timeseries
63
- page2 = Page("timeseries", "Timeseries")
64
- page2.add("Here is a random time series with cumulative noise.")
65
- page2.add(fig2)
66
- page2.add(df2)
67
-
68
- # Page 3: Summary
69
- page3 = Page("summary", "Summary")
70
- page3.add("Summary and notes can be added here.")
71
- page3.add("StaticDash is a lightweight static dashboard generator.")
72
-
73
- # Page 4: Download
74
- page4 = Page("download", "Download")
75
- page4.add("Here is a button to download a file.")
76
- page4.add_download('./test_file.txt', "Download File")
77
- page4.add_download('./test_file2.txt', "Download Another File")
78
-
79
- # Register pages
80
- dashboard.add_page(page1)
81
- dashboard.add_page(page2)
82
- dashboard.add_page(page3)
83
- dashboard.add_page(page4)
84
-
85
- # Export
86
- dashboard.publish(output_dir="output")
87
- ```
88
-
89
- After running the script, open output/index.html in your browser.
@@ -1,8 +0,0 @@
1
- staticdash/__init__.py,sha256=KqViaDkiQnhBI8-j3hr14umLDmPgddvdB_G1nJeC5Xs,38
2
- staticdash/dashboard.py,sha256=yp3L0tM4jlgdYY7HcN-gLmNrCb3fbr6J5-iy4undbCg,5768
3
- staticdash/assets/css/style.css,sha256=yxD9ElyofR6cPQjas9MkQ8iTTw_3RBjREtCbDDIWJHw,2284
4
- staticdash/assets/js/script.js,sha256=rAGEB9sgv8LGdpA1JLQwYAZVRimpEfFSELKb0fFeATI,1222
5
- staticdash-0.2.0.dist-info/METADATA,sha256=jPAVQqxxvK1XxtD8RebE_hLUsAxo7D_ht2WQl32YnQs,2409
6
- staticdash-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- staticdash-0.2.0.dist-info/top_level.txt,sha256=3MzZU6SptkUkjcHV1cvPji0H4aRzPphLHnpStgGEcxM,11
8
- staticdash-0.2.0.dist-info/RECORD,,