|
230 | 230 | }
|
231 | 231 |
|
232 | 232 | // Store cell data
|
233 |
| -globalThis.qpyodideCellDetails = [{"code":"import numpy as np\n\n# Data for plotting\nt = np.arange(0.0, 2.0, 0.01)\ns = 1 + np.sin(2 * np.pi * t)\n\n# Print t\nprint(f\"Displaying 10 observations of `t`:\\n{t[:10]}\\n\")\n\nprint(\"Showing the first 10 values of `s`:\")\n# The last object in the cell does not need print.\ns[:10]","id":1,"options":{"message":"true","comment":"","dpi":72,"fig-height":5,"classes":"","read-only":"false","label":"","fig-cap":"","out-width":"700px","out-height":"","context":"interactive","results":"markup","output":"true","autorun":"","warning":"true","fig-width":7}},{"code":"import matplotlib.pyplot as plt\n\nfig, ax = plt.subplots()\nax.plot(t, s)\n\nax.set(xlabel='time (s)', ylabel='voltage (mV)',\n title='About as simple as it gets, folks')\nax.grid()\n\nplt.show()","id":2,"options":{"message":"true","comment":"","dpi":72,"fig-height":5,"classes":"","read-only":"false","label":"","fig-cap":"","out-width":"700px","out-height":"","context":"interactive","results":"markup","output":"true","autorun":"","warning":"true","fig-width":7}}]; |
| 233 | +globalThis.qpyodideCellDetails = [{"options":{"label":"","message":"true","warning":"true","out-height":"","read-only":"false","autorun":"","output":"true","fig-cap":"","context":"interactive","out-width":"700px","fig-height":5,"results":"markup","fig-width":7,"comment":"","classes":"","dpi":72},"code":"import numpy as np\n\n# Data for plotting\nt = np.arange(0.0, 2.0, 0.01)\ns = 1 + np.sin(2 * np.pi * t)\n\n# Print t\nprint(f\"Displaying 10 observations of `t`:\\n{t[:10]}\\n\")\n\nprint(\"Showing the first 10 values of `s`:\")\n# The last object in the cell does not need print.\ns[:10]","id":1},{"options":{"label":"","message":"true","warning":"true","out-height":"","read-only":"false","autorun":"","output":"true","fig-cap":"","context":"interactive","out-width":"700px","fig-height":5,"results":"markup","fig-width":7,"comment":"","classes":"","dpi":72},"code":"import matplotlib.pyplot as plt\n\nfig, ax = plt.subplots()\nax.plot(t, s)\n\nax.set(xlabel='time (s)', ylabel='voltage (mV)',\n title='About as simple as it gets, folks')\nax.grid()\n\nplt.show()","id":2}]; |
234 | 234 |
|
235 | 235 |
|
236 | 236 | </script>
|
|
255 | 255 |
|
256 | 256 | // Function to update the status message
|
257 | 257 | globalThis.qpyodideUpdateStatusHeader = function(message) {
|
258 |
| - qpyodideStartupMessage.innerHTML = ` |
| 258 | + |
| 259 | + if (!qpyodideShowStartupMessage) return; |
| 260 | + |
| 261 | + qpyodideStartupMessage.innerHTML = message; |
| 262 | +} |
| 263 | + |
| 264 | +// Status header update with customized spinner message |
| 265 | +globalThis.qpyodideUpdateStatusHeaderSpinner = function(message) { |
| 266 | + |
| 267 | + qpyodideUpdateStatusHeader(` |
259 | 268 | <i class="fa-solid fa-spinner fa-spin qpyodide-icon-status-spinner"></i>
|
260 |
| - <span>${message}</span>`; |
| 269 | + <span>${message}</span> |
| 270 | + `); |
261 | 271 | }
|
262 | 272 |
|
| 273 | + |
263 | 274 | // Function that attaches the document status message
|
264 | 275 | function qpyodideDisplayStartupMessage(showStartupMessage) {
|
265 | 276 | if (!showStartupMessage) {
|
|
354 | 365 |
|
355 | 366 | // Setup a namespace for global scoping
|
356 | 367 | // await loadedPyodide.runPythonAsync("globalScope = {}");
|
| 368 | + |
| 369 | + // Update status to reflect the next stage of the procedure |
| 370 | + qpyodideUpdateStatusHeaderSpinner("Initializing Python Packages"); |
357 | 371 |
|
358 | 372 | // Load the `micropip` package to allow installation of packages.
|
359 | 373 | await mainPyodide.loadPackage("micropip");
|
| 374 | + await mainPyodide.runPythonAsync(`import micropip`); |
| 375 | + |
| 376 | + // Load the `pyodide_http` package to shim uses of `requests` and `urllib3`. |
| 377 | + // This allows for `pd.read_csv(url)` to work flawlessly. |
| 378 | + // Details: https://github.com/coatless-quarto/pyodide/issues/9 |
| 379 | + await mainPyodide.loadPackage("pyodide_http"); |
360 | 380 | await mainPyodide.runPythonAsync(`
|
361 |
| - import micropip |
| 381 | + import pyodide_http |
| 382 | + pyodide_http.patch_all() # Patch all libraries |
362 | 383 | `);
|
363 | 384 |
|
364 | 385 | // Load the `matplotlib` package with necessary environment hook
|
|
375 | 396 | qpyodideSetInteractiveButtonState(
|
376 | 397 | `<i class="fa-solid fa-play qpyodide-icon-run-code"></i> <span>Run Code</span>`,
|
377 | 398 | true
|
378 |
| - ); |
| 399 | + ); |
379 | 400 |
|
380 |
| - if (qpyodideShowStartupMessage) { |
381 |
| - qpyodideStartupMessage.innerText = "🟢 Ready!" |
382 |
| - } |
| 401 | + // Set document status to viable |
| 402 | + qpyodideUpdateStatusHeader( |
| 403 | + "🟢 Ready!" |
| 404 | + ); |
383 | 405 |
|
384 | 406 | // Assign Pyodide into the global environment
|
385 | 407 | globalThis.mainPyodide = mainPyodide;
|
|
0 commit comments