Hello all ! I'm trying to incorporate plotly visua...
# questions
p
Hello all ! I'm trying to incorporate plotly visualizations in my mlflow. I've created a simple function:
Copy code
def make_plotly():
    import plotly.express as px
    df = px.data.iris()
    fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species",
                    size='petal_length', hover_data=['petal_width'])
    fig.show()
    return fig
And created a pipeline where the output of the associated node is stored in the catalog
Copy code
plotly_fig:
  type: kedro_mlflow.io.artifacts.MlflowArtifactDataset
  dataset:
    type: plotly.PlotlyDataset
    filepath: data/08_reporting/plotly.json
    plotly_args:
      type: scatter
After running the pipeline, the fig properly shows up in a tab, then is stored in a json format. However, in mlflow ui, it only appears as the json file (see attached image). • Is there a way to show the plotly fig in mlflow ? Do I miss something ? • Also, what args would you recommend to save and load the plotly fig ?
h
Someone will reply to you shortly. In the meantime, this might help:
h
hey @Philippe Martin it seems like MLflow provides
mlflow.log_artifact
. it is stored in the artifact repository associated with the current MLflow run. These artifacts can then be viewed and downloaded from the MLflow UI. Perhaps this can help to visualise your plotly in MLFlow? https://mlflow.org/docs/latest/traditional-ml/hyperparameter-tuning-with-child-runs/notebooks/logging-plots-in-mlflow.html
p
Unfortunatly no.. the artifacts is well saved as a json file in the artificat repository, but it doesn't show as a plotly figure in the MLflow UI, it shows as a json file. Maybe the error comes from how I stored the figure in the catalog ?
Copy code
plotly_fig:
  type: kedro_mlflow.io.artifacts.MlflowArtifactDataset
  dataset:
    type: plotly.PlotlyDataset
    filepath: data/08_reporting/plotly.json
    plotly_args:
      type: scatter
Thank you for your help
I also tried chaning to type plotly.JSONDataset instead of plotly.PlotlyDataset, but same issue ..
g
Hi @Philippe Martin It is possible to log plotly figure with mlflow so that they show in mlflow UI. The artifact needs to be stored as HTML. Look into mlflow.log_figure. If I recall properly, it should be called that way:
Copy code
mlflow.log_figure(figure=figure, artifact_file=f"{name}.html")
where figure is your plotly figure. I am not just sure how it would work with the plotly dataset.
👍 1
r
The plotly dataset in kedro-datasets returns a figure object, which works well with Kedro-Viz. However, MLflow doesn't support this json format. A great idea would be to create an
plotly.MLFlowDataset
dataset that would return the html as you said.
We are already have a plotly.HTMLDataset
@Philippe Martin, I tried using plotly.HTMLDataset instead of plotly.JSONDataset and it worked shuttle_passenger_capacity_plot_go:
Copy code
type: kedro_mlflow.io.artifacts.MlflowArtifactDataset
  dataset:
    type: plotly.HTMLDataset
    filepath: data/08_reporting/shuttle_passenger_capacity_plot_go.html
🥳 2
K 1
p
Amazing, thank you !!