Hi Bryan,
This is my test script. If I change “script,div = components” to show(row(s, col)) and remove the flask part, I’m able to see the plot and use the drop down menu. But the flask part is ok, as I can just remove the drop down menu and change to the component command to have it working without dropdown menu on flask.
{has too much import because I was testing other possible ways.
from bokeh.layouts import row, column
from bokeh.models import CustomJS, Select
from bokeh.plotting import figure, show
from bokeh.embed import components
from bokeh.plotting import figure
import jinja2
from flask import Flask
from bokeh.models import ColumnDataSource, NumeralTickFormatter
from bokeh.palettes import Category20
from bokeh.layouts import gridplot
import pandas as pd
from bokeh.models import ColumnDataSource, HoverTool, Legend
from bokeh.plotting import figure, show
from bokeh.palettes import Category10
import random
import string
from bokeh.resources import CDN
p1 = figure()
p1.circle([1,2,3], [1,3,2], size=20)
p2 = figure(visible=False)
p2.line([1,2,3], [1,3,2], line_width=3)
col = column(p1, p2)
s = Select(value="circle", options=["circle", "line"])
s.js_on_change('value', CustomJS(args=dict(s=s, col=col), code="""
for (const plot of col.children) {
plot.visible = false
}
if (s.value == "circle") {
col.children[0].visible = true
}
else if (s.value == "line") {
col.children[1].visible = true
}
"""))
script,div = components(row(s, col))
resources=CDN.render()
template = jinja2.Template("""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-2.4.3.min.js"></script>
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-2.4.3.min.css">
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-2.4.3.js"></script>
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.3.min.js"></script>
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.3.min.js"></script>
{{resources|safe}}
{{script|safe}}
<title>Bokeh Charts</title>
</head>
<body>
<div class="container">
<h1 class="text-center py-4">Responsive Chart with Bokeh, Flask and Python</h1>
<div class="row mb-5">
<div>
{{ div | safe }}
</div>
</div>
</body>
</html>""")
app = Flask(__name__)
@app.route('/')
def hello_bokeh():
return template.render(script=script, div=div)
if __name__ == '__main__':
app.run(debug=True)