Skip to content

Commit

Permalink
Fix altair examples by gutting soft_dependency hack (#186)
Browse files Browse the repository at this point in the history
* Fix altair examples by gutting soft_dependency hack

* Upgrade shinylive extension

* Try adding jsonschema_specifications to requirements

* 🤦

* try the soft_dependencies import hack again
  • Loading branch information
cpsievert authored Jul 24, 2024
1 parent 6fe5930 commit 4eaa7aa
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
4 changes: 2 additions & 2 deletions _extensions/quarto-ext/shinylive/_extension.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion _extensions/quarto-ext/shinylive/shinylive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
)
Expand Down
42 changes: 30 additions & 12 deletions docs/jupyter-widgets.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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"
Expand All @@ -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
```


Expand Down
9 changes: 6 additions & 3 deletions docs/overview.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down

0 comments on commit 4eaa7aa

Please sign in to comment.