HELP, generate python graph in shiny

hello I want to create a shiny graph generated by python but it does not show it to me in shinyapp

code shiny



library(shiny)


source_python("calculo.py")

ui <- pageWithSidebar(
  headerPanel("renderImage example"),
  sidebarPanel(
    sliderInput("obs", "Number of observations:",
                min = 0, max = 1000,  value = 500)
  ),
  mainPanel(
    # Use imageOutput to place the image on the page
    imageOutput("myImage")
  )
)
server <- function(input, output) {
  
  lm_map_prod_filter <- reactive({
    lm_map_prod_corn[lm_map_prod_corn$farmer == input$farmer,]
  })
  
  output$mapprodPlot <- renderImage({
    map_harvest(lm_map_prod_filter())
    img(src = 'myplot.png')
  })
  
}

shinyApp(ui, server)

code 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()
plt.savefig('myplot.png')

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.