From 4eaa7aa53a71689729357556d26939669c49cb24 Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Wed, 24 Jul 2024 09:32:04 -0500 Subject: [PATCH] Fix altair examples by gutting soft_dependency hack (#186) * Fix altair examples by gutting soft_dependency hack * Upgrade shinylive extension * Try adding jsonschema_specifications to requirements * :facepalm: * try the soft_dependencies import hack again --- .../quarto-ext/shinylive/_extension.yml | 4 +- .../quarto-ext/shinylive/shinylive.lua | 12 +++++- docs/jupyter-widgets.qmd | 42 +++++++++++++------ docs/overview.qmd | 9 ++-- 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/_extensions/quarto-ext/shinylive/_extension.yml b/_extensions/quarto-ext/shinylive/_extension.yml index 01b4d68b..6634416d 100644 --- a/_extensions/quarto-ext/shinylive/_extension.yml +++ b/_extensions/quarto-ext/shinylive/_extension.yml @@ -1,8 +1,8 @@ name: shinylive title: Embedded Shinylive applications author: Winston Chang -version: 0.1.0 -quarto-required: ">=1.2.198" +version: 0.2.0 +quarto-required: ">= 1.2.198" contributes: filters: - shinylive.lua diff --git a/_extensions/quarto-ext/shinylive/shinylive.lua b/_extensions/quarto-ext/shinylive/shinylive.lua index e2828db6..6890a7a3 100644 --- a/_extensions/quarto-ext/shinylive/shinylive.lua +++ b/_extensions/quarto-ext/shinylive/shinylive.lua @@ -393,6 +393,16 @@ function getShinyliveBaseDeps(language) return deps end +-- Legacy quarto cli location +quarto_cli_path = "quarto" +if quarto.config ~= nil and quarto.config.cli_path ~= nil then + -- * 2024/05/03 - Christophe: + -- `quarto run` needs to be called using the same quarto CLI that called the extension. + -- This is done by using `quarto.config.cli_path()` from Quarto 1.5 Lua API. + -- https://github.com/quarto-dev/quarto-cli/pull/9576 + quarto_cli_path = quarto.config.cli_path() +end + return { { CodeBlock = function(el) @@ -415,7 +425,7 @@ return { -- Convert code block to JSON string in the same format as app.json. local parsedCodeblockJson = pandoc.pipe( - "quarto", + quarto_cli_path, { "run", codeblockScript, language }, el.text ) diff --git a/docs/jupyter-widgets.qmd b/docs/jupyter-widgets.qmd index 6e4cb7e3..06a27e6c 100644 --- a/docs/jupyter-widgets.qmd +++ b/docs/jupyter-widgets.qmd @@ -58,29 +58,30 @@ from shiny.express import input, ui from shinywidgets import render_altair import soft_dependencies -ui.input_selectize( - "var", "Select variable", - choices=["bill_length_mm", "body_mass_g"] -) +ui.input_selectize("var", "Select variable", choices=["bill_length_mm", "body_mass_g"]) + @render_altair def hist(): import altair as alt from palmerpenguins import load_penguins df = load_penguins() - return alt.Chart(df).mark_bar().encode( - x=alt.X(f"{input.var()}:Q", bin=True), - y="count()" + return ( + alt.Chart(df) + .mark_bar() + .encode(x=alt.X(f"{input.var()}:Q", bin=True), y="count()") ) ## file: requirements.txt altair anywidget palmerpenguins jsonschema +jsonschema - specifications ## file: soft_dependencies.py # Temporary workaround to inform shinylive of soft dependencies import anywidget import jsonschema +import jsonschema_specifications import mypy_extensions import toolz ``` @@ -393,6 +394,7 @@ import altair as alt from shiny.express import render from shinywidgets import reactive_read, render_altair from vega_datasets import data +import soft_dependencies "Click the legend to update the selection" @@ -404,15 +406,31 @@ def selection(): @render_altair def jchart(): brush = alt.selection_point(name="point", encodings=["color"], bind="legend") - return alt.Chart(data.cars()).mark_point().encode( - x='Horsepower:Q', - y='Miles_per_Gallon:Q', - color=alt.condition(brush, 'Origin:N', alt.value('grey')), - ).add_params(brush) + return ( + alt.Chart(data.cars()) + .mark_point() + .encode( + x="Horsepower:Q", + y="Miles_per_Gallon:Q", + color=alt.condition(brush, "Origin:N", alt.value("grey")), + ) + .add_params(brush) + ) + + ## file: requirements.txt altair anywidget vega_datasets +jsonschema +jsonschema-specifications +## file: soft_dependencies.py +# Temporary workaround to inform shinylive of soft dependencies +import anywidget +import jsonschema +import jsonschema_specifications +import mypy_extensions +import toolz ``` diff --git a/docs/overview.qmd b/docs/overview.qmd index af61eb33..0c498745 100644 --- a/docs/overview.qmd +++ b/docs/overview.qmd @@ -153,19 +153,22 @@ def hist(): import altair as alt from palmerpenguins import load_penguins df = load_penguins() - return alt.Chart(df).mark_bar().encode( - x=alt.X(f"{input.var()}:Q", bin=True), - y="count()" + return ( + alt.Chart(df) + .mark_bar() + .encode(x=alt.X(f"{input.var()}:Q", bin=True), y="count()") ) ## file: requirements.txt altair anywidget palmerpenguins jsonschema +jsonschema-specifications ## file: soft_dependencies.py # Temporary workaround to inform shinylive of soft dependencies import anywidget import jsonschema +import jsonschema_specifications import mypy_extensions import toolz ```