From 5079e826adfd50d3e573d973828f202635867762 Mon Sep 17 00:00:00 2001 From: Jochem Smit Date: Mon, 2 Dec 2024 13:04:15 +0100 Subject: [PATCH] add pyshiny example --- examples/pyshiny_example.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/pyshiny_example.py diff --git a/examples/pyshiny_example.py b/examples/pyshiny_example.py new file mode 100644 index 0000000..607a7b4 --- /dev/null +++ b/examples/pyshiny_example.py @@ -0,0 +1,26 @@ +from ipymolstar import PDBeMolstar +from shiny import reactive +from shiny.express import input, render, ui +from shinywidgets import reactive_read, render_widget + +ui.input_text("molecule_id", "Molecule id", "1qyn") + + +@render_widget +def molstar(): + view = PDBeMolstar(molecule_id="1qyn") + return view + + +@reactive.effect +def _(): + molecule_id = input.molecule_id() + # check for valid pdb id + if len(molecule_id) == 4: + molstar.widget.molecule_id = input.molecule_id() + + +@render.text +def center(): + event = reactive_read(molstar.widget, "mouseover_event") + return f"Mouseover event: {event}"