Isabel Zimmerman Holistic MLOps for Better Science
Let’s go make things
Create .qmd or .ipynb
The YAML header
---format: html---
---format: htmltitle: Quarto Documentsubtitle: Data Science!author: Daniel Chentoc:truetoc-deph:3code-overflow: scrollcode-line-numbers:trueexecute:echo:truekeep-md:truekeep-ipynb:truejupyter: python3---
#| standalone: true#| viewerHeight: 420from htmltools import cssfrom shiny import App, reactive, render, uifrom shinywidgets import output_widget, reactive_read, register_widgetimport ipyleaflet as Lapp_ui = ui.page_fluid( ui.div( ui.input_slider("zoom", "Map zoom level", value=12, min=1, max=18), ui.output_ui("map_bounds"), style=css( display="flex", justify_content="center", align_items="center", gap="2rem" ), ), output_widget("map"),)def server(input, output, session): # Initialize and display when the session starts (1) map = L.Map(center=(40.758896, -73.985130), zoom=12, scroll_wheel_zoom=True) # Add a distance scale map.add_control(L.leaflet.ScaleControl(position="bottomleft")) register_widget("map", map) # When the slider changes, update the map's zoom attribute (2) @reactive.Effect def _(): map.zoom = input.zoom() # When zooming directly on the map, update the slider's value (2 and 3) @reactive.Effect def _(): ui.update_slider("zoom", value=reactive_read(map, "zoom")) # Everytime the map's bounds change, update the output message (3) @output @render.ui def map_bounds(): center = reactive_read(map, "center") if len(center) == 0: return lat = round(center[0], 4) lon = (center[1] + 180) % 360 - 180 lon = round(lon, 4) return ui.p(f"Latitude: {lat}", ui.br(), f"Longitude: {lon}")app = App(app_ui, server)
Shiny for Python!
“Interactive apps and dashboards made easy-ish”
Joe Cheng
Winston Chang
Python…
Common error
$ quarto preview talk.qmd Starting python3 kernel...Traceback (most recent call last): File "/opt/quarto/share/jupyter/jupyter.py", line 21, in <module> from notebook import notebook_execute, RestartKernel File "/opt/quarto/share/jupyter/notebook.py", line 16, in <module> import nbformatModuleNotFoundError: No module named 'nbformat'Python 3 installation: Version: 3.10.8 Path: /usr/bin/python3 Jupyter: (None)Jupyter is not available in this Python installation.Install with python3 -m pip install jupyter