shinylive pyodide cannot install shiny package for a quarto dashboard

72 Views Asked by At

I am attempting to embed a shinylive app in a quarto dashboard. App will let the user selectize filter a categorical variable in a seaborn barplot.

However, I receive the following error in the panel where the app should appear:

Error starting app!

Traceback (most recent call last):
  File "<exec>", line 362, in _start_app
ModuleNotFoundError: The module 'shiny' is included in the Pyodide distribution, but it is not installed.
You can install it by calling:
  await micropip.install("shiny") in Python, or
  await pyodide.loadPackage("shiny") in JavaScript
See https://pyodide.org/en/stable/usage/loading-packages.html for more details.

Currently, in my _quarto.yml

project:
  type: website
  output-dir: public

website:
  title: "title"
  navbar:
    left:
      - href: index.qmd
        text: Home
      - href: about.qmd
        text: About

format: dashboard

filters:
  - shinylive

jupyter: python3

and my index.qmd

```{python py_load_deps}
#| echo: false

# data munging & viz
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import seaborn as sns
import plotly.express as px
```

## Row

Some explainer text.

## Row

```{shinylive-python}
#| standalone: true

#| title: Grouped Bar Plot - NOV 2023

## file: dat/filename.xlsx

from shiny import *
import pandas as pd
import numpy as np
import seaborn as sns
from pathlib import Path
    
# UI
app_ui = ui.page_fluid(
    ui.input_select(
        "select_items",
        "select items:",
        dat().item.unique().tolist(),
        multiple = True
    ),
    ui.output_plot("plot")
)

# server
def server(input, output, session):
    @reactive.calc
    def dat():
        v_path = Path(__file__).parent.resolve() / "dat/filename.xlsx"
        dict_types = {"item": str, "value": np.float64, "value2": np.float64}
        df_summary = pd.read_excel(v_path, sheet_name="sheet_name", usecols="A:D", dtype=dict_types)
        df_summary_grp = df_summary.melt(id_vars='item', value_vars=['value1', 'value2'])
        df_summary_grp = df_summary_grp.reset_index()

        return df_summary_grp

    @reactive.calc
    def items():
        return dat().item.unique().tolist()

    @output
    @render.plot(alt="Grouped Bar of Items")
    def plot():
        g_ax_item_grp = sns.barplot(y='item', x='values', hue='variable', data=dat().loc[dat()[['item']].isin[input.select_item()]])
        g_ax_item_grp.set_xlabel(None)
        sns.move_legend(g_ax_item_grp, loc="lower center", bbox_to_anchor=(-.4,-.3), ncol=2, title=None, frameon=False)
        return g_ax_item_grp

# app
app = App(app_ui, server)

```

I have verified that all packages are installed, and have tried adding micropip.install('shiny') to the shinylive block as specified in the error message, but to no avail.

Thanks in advance for any help!

0

There are 0 best solutions below