|
| 1 | + |
1 | 2 | ^:kindly/hide-code |
2 | 3 | ^{:kindly/options {:html/deps [:scittle :reagent]} |
3 | 4 | :clay {:title "Python + ClojureScript: Pyodide Integration with Scittle" |
|
61 | 62 |
|
62 | 63 | ;; **Think of it as Python's REPL, but in your browser.** |
63 | 64 |
|
| 65 | +;; ## Loading Pyodide |
| 66 | + |
| 67 | +;; Before we can run any demos, we need to load Pyodide once. This happens automatically |
| 68 | +;; when you visit this page - the scripts below will load Pyodide from the CDN and |
| 69 | +;; initialize our shared bridge that all demos will use. |
| 70 | + |
| 71 | +^:kindly/hide-code |
| 72 | +(kind/html |
| 73 | + "<script src=\"https://cdn.jsdelivr.net/pyodide/v0.28.3/full/pyodide.js\"></script>") |
| 74 | + |
| 75 | +^:kindly/hide-code |
| 76 | +(kind/html |
| 77 | + "<script type=\"application/x-scittle\" src=\"pyodide_bridge.cljs\"></script>") |
| 78 | + |
64 | 79 | ;; ## Simple Example: Hello Python |
65 | 80 |
|
66 | 81 | ;; Let's start with the simplest possible example - loading Pyodide and running Python code. |
|
74 | 89 |
|
75 | 90 | ;; ### Try It Live |
76 | 91 |
|
| 92 | +^:kindly/hide-code |
77 | 93 | (kind/hiccup |
78 | 94 | [:div#hello-python-demo {:style {:min-height "400px"}} |
79 | | - ;; Load Pyodide CDN first - this provides js/loadPyodide |
80 | | - [:script {:src "https://cdn.jsdelivr.net/pyodide/v0.28.3/full/pyodide.js"}] |
81 | | - ;; Then load the shared Pyodide bridge |
82 | | - [:script {:type "application/x-scittle" |
83 | | - :src "pyodide_bridge.cljs"}] |
84 | | - ;; Finally load the demo |
| 95 | + ;; Load the demo (Pyodide and bridge already loaded globally) |
85 | 96 | [:script {:type "application/x-scittle" |
86 | 97 | :src "hello_python.cljs"}]]) |
87 | 98 |
|
|
108 | 119 |
|
109 | 120 | ;; ### Try It Live |
110 | 121 |
|
| 122 | +^:kindly/hide-code |
111 | 123 | (kind/hiccup |
112 | 124 | [:div#code-editor-demo {:style {:min-height "500px"}} |
113 | 125 | ;; Load the code editor (Pyodide is already loaded from first demo) |
|
127 | 139 |
|
128 | 140 | ;; ### Try It Live |
129 | 141 |
|
| 142 | +^:kindly/hide-code |
130 | 143 | (kind/hiccup |
131 | 144 | [:div#data-visualization-demo {:style {:min-height "700px"}} |
132 | 145 | ;; Load the data visualization demo (uses already-loaded Pyodide) |
|
155 | 168 |
|
156 | 169 | ;; ### Try It Live |
157 | 170 |
|
| 171 | +^:kindly/hide-code |
158 | 172 | (kind/hiccup |
159 | 173 | [:div#pandas-demo {:style {:min-height "700px"}} |
160 | 174 | ;; Load the pandas demo (uses already-loaded Pyodide) |
|
214 | 228 |
|
215 | 229 | ;; ### Try It Live |
216 | 230 |
|
| 231 | +^:kindly/hide-code |
217 | 232 | (kind/hiccup |
218 | 233 | [:div#pandas-viz-demo {:style {:min-height "800px"}} |
219 | 234 | ;; Load the combined pandas + matplotlib workflow demo |
220 | 235 | [:script {:type "application/x-scittle" |
221 | 236 | :src "pandas_viz_demo.cljs"}]]) |
222 | 237 |
|
| 238 | +;; ## Interactive Data Analysis |
| 239 | + |
| 240 | +;; Want to analyze your own data? Upload CSV files and explore them interactively with Pandas! |
| 241 | + |
| 242 | +;; ### Key Features |
| 243 | + |
| 244 | +;; - **CSV Upload** - Drag & drop or click to upload your data files |
| 245 | +;; - **Data Preview** - See your data in formatted tables |
| 246 | +;; - **Statistical Summary** - Automatic descriptive statistics |
| 247 | +;; - **Data Info** - Column types, null counts, memory usage |
| 248 | +;; - **Export Results** - Download processed data as CSV |
| 249 | + |
| 250 | +;; ### What You Can Do |
| 251 | + |
| 252 | +;; The demo processes your CSV data through Pandas and displays: |
| 253 | + |
| 254 | +;; - First 10 rows of your dataset |
| 255 | +;; - Complete statistical summary (mean, std, min, max, quartiles) |
| 256 | +;; - Data types for each column |
| 257 | +;; - Null value counts |
| 258 | +;; - Memory usage information |
| 259 | + |
| 260 | +;; Perfect for quick exploratory data analysis without installing anything! |
| 261 | + |
| 262 | +;; ### Try It Live |
| 263 | + |
| 264 | +^:kindly/hide-code |
| 265 | +(kind/hiccup |
| 266 | + [:div#interactive-data-analysis |
| 267 | + ;; Load the interactive data analysis demo (uses already-loaded Pyodide) |
| 268 | + [:script {:type "application/x-scittle" |
| 269 | + :src "interactive_data_analysis.cljs"}]]) |
| 270 | + |
| 271 | +;; ## Time Series Analysis |
| 272 | + |
| 273 | +;; Analyze temporal patterns with moving averages, trends, and volatility using Pandas and Matplotlib! |
| 274 | + |
| 275 | +;; ### Two Complete Examples |
| 276 | + |
| 277 | +;; **📈 Stock Market Analysis:** |
| 278 | + |
| 279 | +;; - Price trends with 5-day and 10-day moving averages |
| 280 | +;; - Daily returns (percentage changes) |
| 281 | +;; - Trading volume analysis |
| 282 | +;; - 5-day rolling volatility (risk measurement) |
| 283 | + |
| 284 | +;; **🌡️ Sensor Data Analysis:** |
| 285 | + |
| 286 | +;; - Temperature and humidity patterns over 24 hours |
| 287 | +;; - 3-hour moving averages for trend smoothing |
| 288 | +;; - Correlation analysis (temperature vs humidity) |
| 289 | +;; - Daily pattern visualization |
| 290 | + |
| 291 | +;; ### Time Series Techniques |
| 292 | + |
| 293 | +;; - **Moving Averages** - Smooth out noise to reveal trends |
| 294 | +;; - **Returns Analysis** - Calculate daily percentage changes |
| 295 | +;; - **Volatility Metrics** - Measure fluctuation using rolling standard deviation |
| 296 | +;; - **Correlation Analysis** - Understand relationships between variables |
| 297 | +;; - **Pattern Recognition** - Detect daily/seasonal patterns |
| 298 | + |
| 299 | +;; ### What You'll Learn |
| 300 | + |
| 301 | +;; - How to calculate and visualize moving averages |
| 302 | +;; - Identifying trend direction and potential reversals |
| 303 | +;; - Measuring market/data stability and risk |
| 304 | +;; - Understanding inverse correlations in environmental data |
| 305 | +;; - Analyzing complete 24-hour cycles |
| 306 | + |
| 307 | +^:kindly/hide-code |
| 308 | +(kind/hiccup |
| 309 | + [:div#time-series-analysis |
| 310 | + ;; Load the time series analysis demo (uses already-loaded Pyodide) |
| 311 | + [:script {:type "application/x-scittle" |
| 312 | + :src "time_series_demo.cljs"}]]) |
| 313 | + |
223 | 314 | ;; ## What's Possible? |
224 | 315 |
|
225 | 316 | ;; With Pyodide + Scittle, you can: |
|
230 | 321 | ;; - 🐼 **Data Analysis** - Process and analyze data with Pandas DataFrames |
231 | 322 | ;; - 📈 **Statistical Analysis** - Descriptive statistics, correlations, grouping |
232 | 323 | ;; - 🎯 **Complete Workflows** - Combine pandas analysis with matplotlib visualizations |
| 324 | +;; - 📂 **File Upload & Processing** - Analyze your own CSV data files |
| 325 | +;; - 📉 **Time Series Analysis** - Moving averages, trends, volatility, and patterns |
233 | 326 | ;; - 🎨 **Custom UIs** - Wrap Python functionality in beautiful ClojureScript UIs |
234 | 327 |
|
235 | 328 | ;; ## Next Steps |
236 | 329 |
|
237 | | -;; Explore more advanced features: |
| 330 | +;; Want to dive deeper? Try: |
| 331 | + |
| 332 | +;; - Experimenting with the Interactive Data Analysis demo above - upload your own CSV files! |
| 333 | +;; - Exploring the Time Series Analysis demo - switch between stock and sensor data |
| 334 | +;; - Modifying the code in any demo to create your own visualizations |
238 | 335 |
|
239 | | -;; - Advanced pandas operations (joins, pivots, time series) |
240 | | -;; - Interactive data exploration with dynamic filtering |
| 336 | +;; Or explore advanced topics: |
| 337 | + |
| 338 | +;; - Advanced pandas operations (joins, pivots, time series decomposition) |
241 | 339 | ;; - Machine learning with scikit-learn |
242 | 340 | ;; - Custom Python packages and modules |
| 341 | +;; - Building complete data science applications |
243 | 342 |
|
244 | 343 | ;; --- |
245 | 344 |
|
246 | 345 | ;; ## Acknowledgments |
247 | 346 |
|
248 | 347 | ;; A special thanks to [Timothy Pratley](https://github.com/timothypratley) for creating ClojureCivitas - a welcoming space where the Clojure community can come together to share knowledge, experiences, and our collective love for the Clojure/ClojureScript ecosystem. Projects like this thrive when we have platforms to showcase what's possible and inspire others to explore. |
249 | 348 |
|
| 349 | +;; Huge appreciation to [Daniel Slutsky](https://github.com/daslu) for co-creating and maintaining the incredible [Scicloj](https://scicloj.github.io/) ecosystem of tools - including Clay, Kindly, and many other libraries that make sharing and exploring data in Clojure not just easier, but genuinely fun. This article wouldn't exist without Clay's elegant approach to literate programming and data visualization. |
| 350 | + |
250 | 351 | ;; --- |
251 | 352 |
|
252 | 353 | ;; **Questions?** Find me on Clojurians Slack (@agilecreativity) |
|
0 commit comments