I'm trying to plot a chart in R shiny using python matplotlib, but I couldn't find a way to do this. I created a function in python and I call from R.
Here is my function .py
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
def map_harvest(df):
df = pd.DataFrame.from_dict(df)
treats = list(set(df['yldPlt']))
treats.sort(key=lambda a: (float(a[1:-1].split(',')[0]), float(a[1:-1].split(',')[1])))
color = ['red','orange','yellow', '#00cc00', 'lightgreen','blue']
fig, ax= plt.subplots()
ax.set_aspect('equal')
data = list()
for idx, t in enumerate(treats):
data=np.array(list([g[1],g[2]] for g in zip(df['yldPlt'],df['x'], df['y']) if g[0] == t))
plt.scatter(data[:,0],data[:,1], c = color[idx], s = 0.5, label = treats[idx])
legend = plt.legend(title = "t/ha")
for i in range (len(treats)):
legend.legendHandles[i]._sizes = [30]
ax.set_xticks([])
ax.set_yticks([])
plt.title('Mapa de Produtividade')
fig.tight_layout()
plt.show()
Hi @lariteixeira, my hunch is that you'll want to use renderImage()/imageOutput() instead of renderPlot()/plotOutput(). The former is capable of rendering any image that resides on disk (or as a base64 encoded string) whereas the latter is designed specifically for the R graphics device.