-
Notifications
You must be signed in to change notification settings - Fork 100
Using Lets-plot chart in Shiny #448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as duplicate.
This comment was marked as duplicate.
Here's a more minimal version using Shiny Express, and the more official import lets_plot as lp
import pandas as pd
from shiny.express import input, render, ui
datasets = {
"iris": {
"name": "Iris",
"url": "https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv",
},
"mpg": {
"name": "Mpg",
"url": "https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv",
},
}
with ui.sidebar():
ui.input_selectize(
"dataset", "Dataset", {k: v.get("name") for k, v in datasets.items()}
)
@render.ui
def letsplot():
selection = input.dataset()
df = pd.read_csv(datasets[selection]["url"])
if selection == "iris":
p = (
lp.ggplot(df)
+ lp.geom_point(
lp.aes("petal_length", "petal_width", color="species"), size=5
)
+ lp.ggsize(1000, 500)
)
elif selection == "mpg":
p = (
lp.ggplot(df, lp.aes("displ", "cty", fill="drv", size="hwy"))
+ lp.geom_point(shape=21, color="white")
+ lp.scale_size(range=[5, 15], breaks=[15, 40])
+ lp.ggsize(1000, 500)
)
else:
raise ValueError(f"{selection=} is not valid.")
return ui.HTML(p.to_html(iframe=True)) |
This works great, thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is possible to use lets-plot in shiny? Lets-plot is an interactive version of the grammar of graphic in Python.
The text was updated successfully, but these errors were encountered: