Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick committed Jul 29, 2024
1 parent 8058780 commit e179584
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
28 changes: 25 additions & 3 deletions marimo/_plugins/ui/_impl/from_anywidget.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations

import json
import weakref
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, Optional

import marimo._output.data.data as mo_data
from marimo import _loggers
from marimo._output.rich_help import mddoc
from marimo._plugins.core.json_encoder import WebComponentEncoder
from marimo._plugins.ui._core.ui_element import UIElement
from marimo._runtime.functions import Function

Expand Down Expand Up @@ -86,12 +88,32 @@ def __init__(self, widget: "AnyWidget"):
"tabbable",
"tooltip",
"keys",
"_esm",
"_anywidget_id",
"_dom_classes",
"_model_module",
"_model_module_version",
"_model_name",
"_property_lock",
"_states_to_send",
"_view_count",
"_view_module",
"_view_module_version",
"_view_name",
]
# Remove ignored traits
for trait_name in ignored_traits:
args.pop(trait_name, None)
# Remove all private traits
args = {k: v for k, v in args.items() if not k.startswith("_")}
# Keep only classes that are json serialize-able
json_args: T = {}
for k, v in args.items():
try:
# Try to see if it is json-serializable
json.dumps(v, cls=WebComponentEncoder)
# Just add the plain value, it will be json-serialized later
json_args[k] = v
except TypeError:
pass

def on_change(change: T) -> None:
for key, value in change.items():
Expand All @@ -104,7 +126,7 @@ def on_change(change: T) -> None:

super().__init__(
component_name="marimo-anywidget",
initial_value=args,
initial_value=json_args,
label="",
args={
"js-url": mo_data.js(js).url if js else "", # type: ignore [unused-ignore] # noqa: E501
Expand Down
37 changes: 37 additions & 0 deletions marimo/_smoke_tests/quak-demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import marimo

__generated_with = "0.7.12"
app = marimo.App(width="medium")


@app.cell
def __():
import marimo as mo
import polars as pl
import quak
from vega_datasets import data
return data, mo, pl, quak


@app.cell
def __(data):
df = data.cars()
return df,


@app.cell
def __(df, mo, quak):
qwidget = quak.Widget(df)
w = mo.ui.anywidget(qwidget)
w
return qwidget, w


@app.cell
def __():
# w.value
return


if __name__ == "__main__":
app.run()

0 comments on commit e179584

Please sign in to comment.