Controls
Plotly
Controls
Plotly
Plotly Control
This control is view-only. It is not interactive.
Experimental, may not behave as expected.
from mirmod.controls import Plotly
Plotly()
Example: Plotly Bar Chart
from mirmod.controls import Plotly
from mirmod import miranda
import json
import plotly.express as px
@wob.init()
def init(self):
self.df = None
@wob.receiver("data", "Dataset")
def set_dataset(self, i):
self.df = i
@wob.receiver("state","plotly",control=Plotly(),hidden=True,connectable=False)
def get_plotly(self,plotly_data):
pass
@wob.execute()
def execute(self):
fig = px.bar(self.df)
fig_json = fig.to_json()
ecx = miranda.get_execution_context()
ob = ecx.get_current_wob()
sc = ecx.get_security_context()
# Magic code to update the plotly control,
# will be replaced with a more user-friendly API in the future.
miranda.update_api(
sc, ob,
"RECEIVER", "plotly", "state",
value=fig_json,
connectable=False,
hidden=True
)
# Notifies the GUI to fetch the updated plotly control
miranda.notify_gui(sc, json.dumps({
"action": "update[VIEW]",
"data": { "id": ob.id, "metadata_id" : ob.metadata_id }
}))
On this page