Hi,
I just wonder if there would be possible to render charts via integray + python pandas? The idea was to give some data on input and return chart on output as base64 and than in next step render it as html.
My questions are:
would that be even possible?
how to convert image in base 64 in html connector? Or how else get chart from python-step to html-step?
for rendering charts with pandas, you also need to import matplotlib.pyplot, but that is not allowed in integray. Would that be possible in future? (Chart visualization — pandas 2.2.0 documentation)
currently, we do not offer the matplotlib package as part of the Python processor connector. However, it will be added in the near future. Once matplotlib is available, we will update you in this thread.
Assuming we have the matplotlib package available, the solution can be implemented as follows:
Using the Python processor connector, prepare the necessary plot and then convert it to base64 before returning it.
import io
import base64
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
# Sample DataFrame
data = {
"Category": ["A", "B", "C", "D"],
"Value": [10, 25, 15, 30],
}
df = pd.DataFrame(data)
# Generate a bar plot
plt.bar(df["Category"], df["Value"])
plt.xlabel("Category")
plt.ylabel("Value")
plt.title("Bar Plot")
# Save the plot to a BytesIO object
image_stream = io.BytesIO()
plt.savefig(image_stream, format="png", bbox_inches="tight")
image_stream.seek(0)
# Convert the plot to base64
base64_image = base64.b64encode(image_stream.read()).decode("utf-8")
return [{ "img": base64_image }]
Using the HTML Creator connector, assemble an HTML where the output from the previous step is inserted into an img HTML element, specifying that the data is of type base64.
As you mentioned, direct import of modules from packages, such as import a.b, is not allowed. However, importing specific elements using from an import b is permitted. Importing a.b.c and so on is allowed, but only for allowed modules.