Bokeh Plot Not Displaying in a Django webpage: "Plot has no renderers: figure(id='p1190', ...)"

I am trying to build a Django web application where user can upload an excel file and scatter plot can be displayed. But when I upload the excel file, nothing displays on the webpage. Here is the code for views.py: (I checked using show(p), it works but not displays on webpage asI try to do)

</>

myapp/views.py

from django.shortcuts import render
from bokeh.plotting import figure, show
from bokeh.resources import CDN
from bokeh.embed import components
from pandas import read_excel
from .forms import UploadFileForm

def upload_file(request):
if request.method == ‘POST’ and request.FILES[‘myfile’]:
# get the uploaded file
myfile = request.FILES[‘myfile’]

    # read the excel file data using pandas
    df = read_excel(myfile, sheet_name='Sheet1')

    # create a scatter plot using Bokeh
    p = figure(title="Scatter Plot", x_axis_label='X', y_axis_label='Y')
   #p.circle(df['x'].to_list(), df['y'].to_list(), size=10)
    p.circle(df['x'], df['y'], size=10)
    
    
    
    # generate Bokeh components
    script, div = components(p, CDN)

    # render the template with the Bokeh components and file upload form
    return render(request, 'upload.html', {'script': script, 'div': div, 'form': UploadFileForm()})

# if the request method is not POST or no file is uploaded, create an empty Bokeh plot object
else:
    # create an empty scatter plot using Bokeh
    p = figure(title="Scatter Plot", x_axis_label='X', y_axis_label='Y')

    # generate Bokeh components with the empty plot object
    script, div = components(p, CDN)

    # render the template with the Bokeh components and file upload form
    return render(request, 'upload.html', {'script': script, 'div': div, 'form': UploadFileForm()})

</>

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