Bokeh Server Integration with Flask error

Hello,

I’m stuck at a point where I try to integrate my bokeh server app with Flask. I am using the GMapOptions library in bokeh to generate a visualization showing the distribution of my client data across a geographical area. I get the following error when I run the Flask app code,

TypeError: init() missing 2 required positional arguments: ‘google_api_key’ and ‘map_options’

``

I get the same message in the command prompt when I run the bokeh server app independently in the command prompt using the bokeh serve command, but the app runs nevertheless.

Here is my code for the visualization,


coding: utf-8

In[1]:

from bokeh.plotting import figure, output_file, show, gmap
from bokeh.models import *
from bokeh.io import output_notebook, curdoc
from bokeh.transform import factor_cmap
from bokeh.layouts import column, row
import pandas as pd
import numpy as np
import pyodbc

output_file(“gmap.html”)

parameters

server = ‘X.X.X.X\PQR’
db = ‘abc’

Create the connection

conn = pyodbc.connect(‘DRIVER={SQL Server};SERVER=’ + server + ‘;DATABASE=’ + db + ‘;Trusted_Connection=yes’)

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type=“roadmap”, zoom=13)
p = gmap(“My Google Maps API Key”, map_options, title=“Resolutions Clients”, plot_width=1000, plot_height=600)

sql = “”"
with CTE AS
(SELECT
CR.ClientID, CR.Latitude, CR.Longtitude
FROM
Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
WHERE
C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
)
SELECT
C.ClientID, C.Latitude, C.Longtitude, CL.Sex
FROM
CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
“”"
df = pd.read_sql(sql, conn)

df[[‘Latitude’, ‘Longtitude’]] = df[[‘Latitude’, ‘Longtitude’]].apply(pd.to_numeric)
df[‘Sex’] = df[‘Sex’].astype(‘str’)

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type=“roadmap”, zoom=10)
p = gmap(“My Google Maps API Key”, map_options, title=“Resolutions Clients Genderwise”, plot_width=1000,
plot_height=600)

lat = df[‘Latitude’].tolist()
lon = df[‘Longtitude’].tolist()
sex = df[‘Sex’].tolist()

source = ColumnDataSource(
data=dict(latitude=lat,
longitude=lon,
gender=sex
)
)

color_mapper = CategoricalColorMapper(factors=[‘M’, ‘F’, ‘U’], palette=[‘Red’, ‘Blue’, ‘Green’])

p.circle(x=“longitude”, y=“latitude”, size=4, fill_alpha=0.9, source=source,
fill_color={‘field’: ‘gender’, ‘transform’: color_mapper},
line_color={‘field’: ‘gender’, ‘transform’: color_mapper})

x = np.linspace(0, 4 * np.pi, 100)
y = np.sin(x)

p.circle(x, y, legend=“Male”, color=“red”)
p.circle(x, 2 * y, legend=“Female”, color=“Blue”)
p.circle(x, 3 * y, legend=“Unknown”, color=“Green”)

def update():
# query db
curdoc().clear()
sql = “”"
with CTE AS
(SELECT
CR.ClientID, CR.Latitude, CR.Longtitude
FROM
Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
WHERE
C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
)
SELECT
C.ClientID, C.Latitude, C.Longtitude,
CASE WHEN age > 0 AND age <= 15 THEN ‘Children’
WHEN age > 15 AND age <= 30 THEN ‘Young Adult’
WHEN age > 30 AND age <= 55 THEN ‘Adult’
WHEN age > 55 THEN ‘Senior Citizen’
END AS ‘Age_Group’
FROM
CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
“”"
df = pd.read_sql(sql, conn)

df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
df['Age_Group'] = df['Age_Group'].astype('str')

df['Latitude'].median()
df['Longtitude'].median()

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)

p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Age wise",
         plot_width=1000, plot_height=600)

lat = df['Latitude'].tolist()
lon = df['Longtitude'].tolist()
age = df['Age_Group'].tolist()

source = ColumnDataSource(
    data=dict(latitude=lat,
              longitude=lon,
              age_Group=age
              )
)

color_mapper = CategoricalColorMapper(factors=['Children', 'Young Adult', 'Adult', 'Senior Citizen'],
                                      palette=['Red', 'Blue', 'Green', 'Yellow'])

p.add_tools(LassoSelectTool())
p.add_tools(ZoomInTool())
p.add_tools(ZoomOutTool())

p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
         fill_color={'field': 'age_Group', 'transform': color_mapper},
         line_color={'field': 'age_Group', 'transform': color_mapper})

x = np.linspace(0, 4 * np.pi, 100)
y = np.sin(x)

p.circle(x, y, legend="Children : Age <= 15", color="red")
p.circle(x, 2 * y, legend="Young Adult : 30 >= Age > 15", color="Blue")
p.circle(x, 3 * y, legend="Adult : 55 >= Age > 30 ", color="Green")
p.circle(x, 4 * y, legend="Senior Citizen : Age > 55", color="Yellow")

curdoc().add_root(row(button1, button2))
curdoc().add_root(column(p))

def update1():
# query db
curdoc().clear()
sql = “”"
with CTE AS
(SELECT
CR.ClientID, CR.Latitude, CR.Longtitude
FROM
Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
WHERE
C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
)
SELECT
C.ClientID, C.Latitude, C.Longtitude, CL.Sex
FROM
CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
“”"
df = pd.read_sql(sql, conn)

df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
df['Sex'] = df['Sex'].astype('str')

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)
p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Genderwise",
         plot_width=1000,
         plot_height=600)

lat = df['Latitude'].tolist()
lon = df['Longtitude'].tolist()
sex = df['Sex'].tolist()

source = ColumnDataSource(
    data=dict(latitude=lat,
              longitude=lon,
              gender=sex
              )
)

color_mapper = CategoricalColorMapper(factors=['M', 'F', 'U'], palette=['Red', 'Blue', 'Green'])

p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
         fill_color={'field': 'gender', 'transform': color_mapper},
         line_color={'field': 'gender', 'transform': color_mapper})

x = np.linspace(0, 4 * np.pi, 100)
y = np.sin(x)

p.circle(x, y, legend="Male", color="red")
p.circle(x, 2 * y, legend="Female", color="Blue")
p.circle(x, 3 * y, legend="Unknown", color="Green")

curdoc().add_root(row(button1, button2))
curdoc().add_root(column(p))

add a button widget and configure with the call back

button1 = Button(label=“Gender”)
button2 = Button(label=“Age”)

button1.on_click(update1)
button2.on_click(update)

put the button and plot in a layout and add to the document

curdoc().add_root(row(button1, button2))
curdoc().add_root(column(p))


Here is my app.py file
from flask import Flask, render_template
from bokeh.embed import autoload_static
from bokeh.client import pull_session

#instantiating the flask app
app = Flask(__name__)

#create the index page function

@app.route("/")
def index():
 session = pull_session(url="http://localhost:5006/Button_test_update_version2")
 bokeh_script = autoload_static(None, url="http://localhost:5006/Button_test_update_version2", session_id=session.id)
 return render_template("index.html", bokeh_script=bokeh_script)

#run the app
if __name__ == "_main_":

Here is my index.html file,
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ABC Visualization</title>
    <link rel="stylesheet" href={‌{url_for('static', filename='css/main.css')}}>
</head>
<body>
<h1>ABC Visualization</h1>
<div>
    {‌{bokeh_script|safe}}
</div>
</body>
</html>

Here is my main.css file,


h3{
color : olive;
}

I'm not sure what the underlying issue is, but this seems familiar and my recollection is that things will work if you pass those two values as keyword arguments instead.

Thanks,

Bryan

···

On Jun 15, 2018, at 11:11, anuj nimkar <[email protected]> wrote:

Hello,
I'm stuck at a point where I try to integrate my bokeh server app with Flask. I am using the GMapOptions library in bokeh to generate a visualization showing the distribution of my client data across a geographical area. I get the following error when I run the Flask app code,

TypeError: __init__() missing 2 required positional arguments: 'google_api_key' and 'map_options'

I get the same message in the command prompt when I run the bokeh server app independently in the command prompt using the bokeh serve command, but the app runs nevertheless.

Here is my code for the visualization,

# coding: utf-8

# In[1]:

from bokeh.plotting import figure, output_file, show, gmap
from bokeh.models import *
from bokeh.io import output_notebook, curdoc
from bokeh.transform import factor_cmap
from bokeh.layouts import column, row
import pandas as pd
import numpy as np
import pyodbc

output_file("gmap.html")

# parameters
server = 'X.X.X.X\PQR'
db = 'abc'

# Create the connection
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=' + server + ';DATABASE=' + db + ';Trusted_Connection=yes')

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=13)
p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients", plot_width=1000, plot_height=600)

sql = """
        with CTE AS
            (SELECT
            CR.ClientID, CR.Latitude, CR.Longtitude
            FROM
            Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
            WHERE
            C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
            )
        SELECT
        C.ClientID, C.Latitude, C.Longtitude, CL.Sex
        FROM
        CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
    """
df = pd.read_sql(sql, conn)

df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
df['Sex'] = df['Sex'].astype('str')

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)
p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Genderwise", plot_width=1000,
             plot_height=600)

lat = df['Latitude'].tolist()
lon = df['Longtitude'].tolist()
sex = df['Sex'].tolist()

source = ColumnDataSource(
        data=dict(latitude=lat,
                  longitude=lon,
                  gender=sex
                  )
)

color_mapper = CategoricalColorMapper(factors=['M', 'F', 'U'], palette=['Red', 'Blue', 'Green'])

p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
             fill_color={'field': 'gender', 'transform': color_mapper},
             line_color={'field': 'gender', 'transform': color_mapper})

x = np.linspace(0, 4 * np.pi, 100)
y = np.sin(x)

p.circle(x, y, legend="Male", color="red")
p.circle(x, 2 * y, legend="Female", color="Blue")
p.circle(x, 3 * y, legend="Unknown", color="Green")

def update():
    # query db
    curdoc().clear()
    sql = """
            with CTE AS
                (SELECT
                CR.ClientID, CR.Latitude, CR.Longtitude
                FROM
                Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
                WHERE
                C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
                )
            SELECT
                C.ClientID, C.Latitude, C.Longtitude,
                CASE WHEN age > 0 AND age <= 15 THEN 'Children'
                     WHEN age > 15 AND age <= 30 THEN 'Young Adult'
                     WHEN age > 30 AND age <= 55 THEN 'Adult'
                     WHEN age > 55 THEN 'Senior Citizen'
                     END AS 'Age_Group'
            FROM
            CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
    """
    df = pd.read_sql(sql, conn)

    df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
    df['Age_Group'] = df['Age_Group'].astype('str')

    df['Latitude'].median()
    df['Longtitude'].median()

    map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)

    p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Age wise",
             plot_width=1000, plot_height=600)

    lat = df['Latitude'].tolist()
    lon = df['Longtitude'].tolist()
    age = df['Age_Group'].tolist()

    source = ColumnDataSource(
        data=dict(latitude=lat,
                  longitude=lon,
                  age_Group=age
                  )
    )

    color_mapper = CategoricalColorMapper(factors=['Children', 'Young Adult', 'Adult', 'Senior Citizen'],
                                          palette=['Red', 'Blue', 'Green', 'Yellow'])

    p.add_tools(LassoSelectTool())
    p.add_tools(ZoomInTool())
    p.add_tools(ZoomOutTool())

    p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
             fill_color={'field': 'age_Group', 'transform': color_mapper},
             line_color={'field': 'age_Group', 'transform': color_mapper})

    x = np.linspace(0, 4 * np.pi, 100)
    y = np.sin(x)

    p.circle(x, y, legend="Children : Age <= 15", color="red")
    p.circle(x, 2 * y, legend="Young Adult : 30 >= Age > 15", color="Blue")
    p.circle(x, 3 * y, legend="Adult : 55 >= Age > 30 ", color="Green")
    p.circle(x, 4 * y, legend="Senior Citizen : Age > 55", color="Yellow")

    curdoc().add_root(row(button1, button2))
    curdoc().add_root(column(p))

def update1():
    # query db
    curdoc().clear()
    sql = """
            with CTE AS
                (SELECT
                CR.ClientID, CR.Latitude, CR.Longtitude
                FROM
                Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
                WHERE
                C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
                )
            SELECT
            C.ClientID, C.Latitude, C.Longtitude, CL.Sex
            FROM
            CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
        """
    df = pd.read_sql(sql, conn)

    df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
    df['Sex'] = df['Sex'].astype('str')

    map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)
    p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Genderwise",
             plot_width=1000,
             plot_height=600)

    lat = df['Latitude'].tolist()
    lon = df['Longtitude'].tolist()
    sex = df['Sex'].tolist()

    source = ColumnDataSource(
        data=dict(latitude=lat,
                  longitude=lon,
                  gender=sex
                  )
    )

    color_mapper = CategoricalColorMapper(factors=['M', 'F', 'U'], palette=['Red', 'Blue', 'Green'])

    p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
             fill_color={'field': 'gender', 'transform': color_mapper},
             line_color={'field': 'gender', 'transform': color_mapper})

    x = np.linspace(0, 4 * np.pi, 100)
    y = np.sin(x)

    p.circle(x, y, legend="Male", color="red")
    p.circle(x, 2 * y, legend="Female", color="Blue")
    p.circle(x, 3 * y, legend="Unknown", color="Green")

    curdoc().add_root(row(button1, button2))
    curdoc().add_root(column(p))

# add a button widget and configure with the call back
button1 = Button(label="Gender")
button2 = Button(label="Age")

button1.on_click(update1)
button2.on_click(update)

# put the button and plot in a layout and add to the document

curdoc().add_root(row(button1, button2))
curdoc().add_root(column(p))

Here is my app.py file

from flask import Flask, render_template
from bokeh.embed import autoload_static
from bokeh.client import pull_session

#instantiating the flask app
app = Flask(__name__)

#create the index page function

@app.route("/")
def index():
session = pull_session(url="http://localhost:5006/Button_test_update_version2&quot;\)
bokeh_script = autoload_static(None, url="http://localhost:5006/Button_test_update_version2&quot;, session_id=session.id)
return render_template("index.html", bokeh_script=bokeh_script)

#run the app
if __name__ == "_main_":

Here is my index.html file,
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ABC Visualization</title>
    <link rel="stylesheet" href={‌{url_for('static', filename='css/main.css')}}>
</head>
<body>
<h1>ABC Visualization</h1>
<div>
    {‌{bokeh_script|safe}}
</div>
</body>
</html>

Here is my main.css file,

h3{
    color : olive;
}

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/27d007e3-1222-4795-a6a1-b31506c56cc5%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Yes, see:

  Python Bokeh, Google Maps API Patch Doc error - Stack Overflow

···

On Jun 15, 2018, at 11:11, anuj nimkar <[email protected]> wrote:

Hello,
I'm stuck at a point where I try to integrate my bokeh server app with Flask. I am using the GMapOptions library in bokeh to generate a visualization showing the distribution of my client data across a geographical area. I get the following error when I run the Flask app code,

TypeError: __init__() missing 2 required positional arguments: 'google_api_key' and 'map_options'

I get the same message in the command prompt when I run the bokeh server app independently in the command prompt using the bokeh serve command, but the app runs nevertheless.

Here is my code for the visualization,

# coding: utf-8

# In[1]:

from bokeh.plotting import figure, output_file, show, gmap
from bokeh.models import *
from bokeh.io import output_notebook, curdoc
from bokeh.transform import factor_cmap
from bokeh.layouts import column, row
import pandas as pd
import numpy as np
import pyodbc

output_file("gmap.html")

# parameters
server = 'X.X.X.X\PQR'
db = 'abc'

# Create the connection
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=' + server + ';DATABASE=' + db + ';Trusted_Connection=yes')

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=13)
p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients", plot_width=1000, plot_height=600)

sql = """
        with CTE AS
            (SELECT
            CR.ClientID, CR.Latitude, CR.Longtitude
            FROM
            Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
            WHERE
            C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
            )
        SELECT
        C.ClientID, C.Latitude, C.Longtitude, CL.Sex
        FROM
        CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
    """
df = pd.read_sql(sql, conn)

df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
df['Sex'] = df['Sex'].astype('str')

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)
p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Genderwise", plot_width=1000,
             plot_height=600)

lat = df['Latitude'].tolist()
lon = df['Longtitude'].tolist()
sex = df['Sex'].tolist()

source = ColumnDataSource(
        data=dict(latitude=lat,
                  longitude=lon,
                  gender=sex
                  )
)

color_mapper = CategoricalColorMapper(factors=['M', 'F', 'U'], palette=['Red', 'Blue', 'Green'])

p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
             fill_color={'field': 'gender', 'transform': color_mapper},
             line_color={'field': 'gender', 'transform': color_mapper})

x = np.linspace(0, 4 * np.pi, 100)
y = np.sin(x)

p.circle(x, y, legend="Male", color="red")
p.circle(x, 2 * y, legend="Female", color="Blue")
p.circle(x, 3 * y, legend="Unknown", color="Green")

def update():
    # query db
    curdoc().clear()
    sql = """
            with CTE AS
                (SELECT
                CR.ClientID, CR.Latitude, CR.Longtitude
                FROM
                Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
                WHERE
                C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
                )
            SELECT
                C.ClientID, C.Latitude, C.Longtitude,
                CASE WHEN age > 0 AND age <= 15 THEN 'Children'
                     WHEN age > 15 AND age <= 30 THEN 'Young Adult'
                     WHEN age > 30 AND age <= 55 THEN 'Adult'
                     WHEN age > 55 THEN 'Senior Citizen'
                     END AS 'Age_Group'
            FROM
            CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
    """
    df = pd.read_sql(sql, conn)

    df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
    df['Age_Group'] = df['Age_Group'].astype('str')

    df['Latitude'].median()
    df['Longtitude'].median()

    map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)

    p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Age wise",
             plot_width=1000, plot_height=600)

    lat = df['Latitude'].tolist()
    lon = df['Longtitude'].tolist()
    age = df['Age_Group'].tolist()

    source = ColumnDataSource(
        data=dict(latitude=lat,
                  longitude=lon,
                  age_Group=age
                  )
    )

    color_mapper = CategoricalColorMapper(factors=['Children', 'Young Adult', 'Adult', 'Senior Citizen'],
                                          palette=['Red', 'Blue', 'Green', 'Yellow'])

    p.add_tools(LassoSelectTool())
    p.add_tools(ZoomInTool())
    p.add_tools(ZoomOutTool())

    p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
             fill_color={'field': 'age_Group', 'transform': color_mapper},
             line_color={'field': 'age_Group', 'transform': color_mapper})

    x = np.linspace(0, 4 * np.pi, 100)
    y = np.sin(x)

    p.circle(x, y, legend="Children : Age <= 15", color="red")
    p.circle(x, 2 * y, legend="Young Adult : 30 >= Age > 15", color="Blue")
    p.circle(x, 3 * y, legend="Adult : 55 >= Age > 30 ", color="Green")
    p.circle(x, 4 * y, legend="Senior Citizen : Age > 55", color="Yellow")

    curdoc().add_root(row(button1, button2))
    curdoc().add_root(column(p))

def update1():
    # query db
    curdoc().clear()
    sql = """
            with CTE AS
                (SELECT
                CR.ClientID, CR.Latitude, CR.Longtitude
                FROM
                Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
                WHERE
                C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
                )
            SELECT
            C.ClientID, C.Latitude, C.Longtitude, CL.Sex
            FROM
            CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
        """
    df = pd.read_sql(sql, conn)

    df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
    df['Sex'] = df['Sex'].astype('str')

    map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)
    p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Genderwise",
             plot_width=1000,
             plot_height=600)

    lat = df['Latitude'].tolist()
    lon = df['Longtitude'].tolist()
    sex = df['Sex'].tolist()

    source = ColumnDataSource(
        data=dict(latitude=lat,
                  longitude=lon,
                  gender=sex
                  )
    )

    color_mapper = CategoricalColorMapper(factors=['M', 'F', 'U'], palette=['Red', 'Blue', 'Green'])

    p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
             fill_color={'field': 'gender', 'transform': color_mapper},
             line_color={'field': 'gender', 'transform': color_mapper})

    x = np.linspace(0, 4 * np.pi, 100)
    y = np.sin(x)

    p.circle(x, y, legend="Male", color="red")
    p.circle(x, 2 * y, legend="Female", color="Blue")
    p.circle(x, 3 * y, legend="Unknown", color="Green")

    curdoc().add_root(row(button1, button2))
    curdoc().add_root(column(p))

# add a button widget and configure with the call back
button1 = Button(label="Gender")
button2 = Button(label="Age")

button1.on_click(update1)
button2.on_click(update)

# put the button and plot in a layout and add to the document

curdoc().add_root(row(button1, button2))
curdoc().add_root(column(p))

Here is my app.py file

from flask import Flask, render_template
from bokeh.embed import autoload_static
from bokeh.client import pull_session

#instantiating the flask app
app = Flask(__name__)

#create the index page function

@app.route("/")
def index():
session = pull_session(url="http://localhost:5006/Button_test_update_version2&quot;\)
bokeh_script = autoload_static(None, url="http://localhost:5006/Button_test_update_version2&quot;, session_id=session.id)
return render_template("index.html", bokeh_script=bokeh_script)

#run the app
if __name__ == "_main_":

Here is my index.html file,
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ABC Visualization</title>
    <link rel="stylesheet" href={‌{url_for('static', filename='css/main.css')}}>
</head>
<body>
<h1>ABC Visualization</h1>
<div>
    {‌{bokeh_script|safe}}
</div>
</body>
</html>

Here is my main.css file,

h3{
    color : olive;
}

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/27d007e3-1222-4795-a6a1-b31506c56cc5%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hey Bryan,
Yes I had posted this issue on multiple groups, as I have still not been able to resolve this and have kind of hit the wall at this point. I am passing those two values as arguments.

p = gmap(“My Google Maps API Key”, map_options, title=“Resolutions Clients Genderwise”, plot_width=1000,
plot_height=600)

I’m not sure I understand your answer, but please correct me if I’m misunderstanding.

Thanks!


···

On Friday, 15 June 2018 11:23:38 UTC-7, Bryan Van de ven wrote:

Yes, see:

    [https://stackoverflow.com/questions/50782293/python-bokeh-google-maps-api-patch-doc-error](https://stackoverflow.com/questions/50782293/python-bokeh-google-maps-api-patch-doc-error)

On Jun 15, 2018, at 11:11, anuj nimkar [email protected] wrote:

Hello,

I’m stuck at a point where I try to integrate my bokeh server app with Flask. I am using the GMapOptions library in bokeh to generate a visualization showing the distribution of my client data across a geographical area. I get the following error when I run the Flask app code,

TypeError: init() missing 2 required positional arguments: ‘google_api_key’ and ‘map_options’

I get the same message in the command prompt when I run the bokeh server app independently in the command prompt using the bokeh serve command, but the app runs nevertheless.

Here is my code for the visualization,

coding: utf-8

In[1]:

from bokeh.plotting import figure, output_file, show, gmap

from bokeh.models import *

from bokeh.io import output_notebook, curdoc

from bokeh.transform import factor_cmap

from bokeh.layouts import column, row

import pandas as pd

import numpy as np

import pyodbc

output_file(“gmap.html”)

parameters

server = ‘X.X.X.X\PQR’

db = ‘abc’

Create the connection

conn = pyodbc.connect(‘DRIVER={SQL Server};SERVER=’ + server + ‘;DATABASE=’ + db + ‘;Trusted_Connection=yes’)

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type=“roadmap”, zoom=13)

p = gmap(“My Google Maps API Key”, map_options, title=“Resolutions Clients”, plot_width=1000, plot_height=600)

sql = “”"

    with CTE AS
        (SELECT
        CR.ClientID, CR.Latitude, CR.Longtitude
        FROM
        Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
        WHERE
        C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
        )
    SELECT
    C.ClientID, C.Latitude, C.Longtitude, CL.Sex
    FROM
    CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
"""

df = pd.read_sql(sql, conn)

df[[‘Latitude’, ‘Longtitude’]] = df[[‘Latitude’, ‘Longtitude’]].apply(pd.to_numeric)

df[‘Sex’] = df[‘Sex’].astype(‘str’)

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type=“roadmap”, zoom=10)

p = gmap(“My Google Maps API Key”, map_options, title=“Resolutions Clients Genderwise”, plot_width=1000,

         plot_height=600)

lat = df[‘Latitude’].tolist()

lon = df[‘Longtitude’].tolist()

sex = df[‘Sex’].tolist()

source = ColumnDataSource(

    data=dict(latitude=lat,
              longitude=lon,
              gender=sex
              )

)

color_mapper = CategoricalColorMapper(factors=[‘M’, ‘F’, ‘U’], palette=[‘Red’, ‘Blue’, ‘Green’])

p.circle(x=“longitude”, y=“latitude”, size=4, fill_alpha=0.9, source=source,

         fill_color={'field': 'gender', 'transform': color_mapper},
         line_color={'field': 'gender', 'transform': color_mapper})

x = np.linspace(0, 4 * np.pi, 100)

y = np.sin(x)

p.circle(x, y, legend=“Male”, color=“red”)

p.circle(x, 2 * y, legend=“Female”, color=“Blue”)

p.circle(x, 3 * y, legend=“Unknown”, color=“Green”)

def update():

# query db
curdoc().clear()
sql = """
        with CTE AS
            (SELECT
            CR.ClientID, CR.Latitude, CR.Longtitude
            FROM
            Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
            WHERE
            C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
            )
        SELECT
            C.ClientID, C.Latitude, C.Longtitude,
            CASE WHEN age > 0 AND age <= 15 THEN 'Children'
                 WHEN age > 15 AND age <= 30 THEN 'Young Adult'
                 WHEN age > 30 AND age <= 55 THEN 'Adult'
                 WHEN age > 55 THEN 'Senior Citizen'
                 END AS 'Age_Group'
        FROM
        CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
"""
df = pd.read_sql(sql, conn)
df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
df['Age_Group'] = df['Age_Group'].astype('str')
df['Latitude'].median()
df['Longtitude'].median()
map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)
p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Age wise",
         plot_width=1000, plot_height=600)
lat = df['Latitude'].tolist()
lon = df['Longtitude'].tolist()
age = df['Age_Group'].tolist()
source = ColumnDataSource(
    data=dict(latitude=lat,
              longitude=lon,
              age_Group=age
              )
)
color_mapper = CategoricalColorMapper(factors=['Children', 'Young Adult', 'Adult', 'Senior Citizen'],
                                      palette=['Red', 'Blue', 'Green', 'Yellow'])
p.add_tools(LassoSelectTool())
p.add_tools(ZoomInTool())
p.add_tools(ZoomOutTool())
p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
         fill_color={'field': 'age_Group', 'transform': color_mapper},
         line_color={'field': 'age_Group', 'transform': color_mapper})
x = np.linspace(0, 4 * np.pi, 100)
y = np.sin(x)
p.circle(x, y, legend="Children : Age <= 15", color="red")
p.circle(x, 2 * y, legend="Young Adult : 30 >= Age > 15", color="Blue")
p.circle(x, 3 * y, legend="Adult : 55 >= Age > 30 ", color="Green")
p.circle(x, 4 * y, legend="Senior Citizen : Age > 55", color="Yellow")
curdoc().add_root(row(button1, button2))
curdoc().add_root(column(p))

def update1():

# query db
curdoc().clear()
sql = """
        with CTE AS
            (SELECT
            CR.ClientID, CR.Latitude, CR.Longtitude
            FROM
            Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
            WHERE
            C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
            )
        SELECT
        C.ClientID, C.Latitude, C.Longtitude, CL.Sex
        FROM
        CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
    """
df = pd.read_sql(sql, conn)
df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
df['Sex'] = df['Sex'].astype('str')
map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)
p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Genderwise",
         plot_width=1000,
         plot_height=600)
lat = df['Latitude'].tolist()
lon = df['Longtitude'].tolist()
sex = df['Sex'].tolist()
source = ColumnDataSource(
    data=dict(latitude=lat,
              longitude=lon,
              gender=sex
              )
)
color_mapper = CategoricalColorMapper(factors=['M', 'F', 'U'], palette=['Red', 'Blue', 'Green'])
p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
         fill_color={'field': 'gender', 'transform': color_mapper},
         line_color={'field': 'gender', 'transform': color_mapper})
x = np.linspace(0, 4 * np.pi, 100)
y = np.sin(x)
p.circle(x, y, legend="Male", color="red")
p.circle(x, 2 * y, legend="Female", color="Blue")
p.circle(x, 3 * y, legend="Unknown", color="Green")
curdoc().add_root(row(button1, button2))
curdoc().add_root(column(p))

add a button widget and configure with the call back

button1 = Button(label=“Gender”)

button2 = Button(label=“Age”)

button1.on_click(update1)

button2.on_click(update)

put the button and plot in a layout and add to the document

curdoc().add_root(row(button1, button2))

curdoc().add_root(column(p))

Here is my app.py file

from flask import Flask, render_template

from bokeh.embed import autoload_static

from bokeh.client import pull_session

#instantiating the flask app

app = Flask(name)

#create the index page function

@app.route(“/”)

def index():

session = pull_session(url=“http://localhost:5006/Button_test_update_version2”)

bokeh_script = autoload_static(None, url=“http://localhost:5006/Button_test_update_version2”, session_id=session.id)

return render_template(“index.html”, bokeh_script=bokeh_script)

#run the app

if name == “main”:

Here is my index.html file,

<meta charset="UTF-8">
<title>ABC Visualization</title>
<link rel="stylesheet" href={‌{url_for('static', filename='css/main.css')}}>

ABC Visualization

{‌{bokeh_script|safe}}

Here is my main.css file,

h3{

color : olive;

}


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/27d007e3-1222-4795-a6a1-b31506c56cc5%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

You need to pass them explicitly as keywords, not positionally:

  gmap(google_api_key="My Google Maps API Key", map_options=map_options, ...

Bryan

···

On Jun 15, 2018, at 11:34, anuj nimkar <[email protected]> wrote:

Hey Bryan,
Yes I had posted this issue on multiple groups, as I have still not been able to resolve this and have kind of hit the wall at this point. I am passing those two values as arguments.
p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Genderwise", plot_width=1000,
             plot_height=600)

I'm not sure I understand your answer, but please correct me if I'm misunderstanding.

Thanks!

On Friday, 15 June 2018 11:23:38 UTC-7, Bryan Van de ven wrote:
Yes, see:

        Python Bokeh, Google Maps API Patch Doc error - Stack Overflow

> On Jun 15, 2018, at 11:11, anuj nimkar <[email protected]> wrote:
>
> Hello,
> I'm stuck at a point where I try to integrate my bokeh server app with Flask. I am using the GMapOptions library in bokeh to generate a visualization showing the distribution of my client data across a geographical area. I get the following error when I run the Flask app code,
>
> TypeError: __init__() missing 2 required positional arguments: 'google_api_key' and 'map_options'
>
> I get the same message in the command prompt when I run the bokeh server app independently in the command prompt using the bokeh serve command, but the app runs nevertheless.
>
> Here is my code for the visualization,
>
>
> # coding: utf-8
>
> # In[1]:
>
> from bokeh.plotting import figure, output_file, show, gmap
> from bokeh.models import *
> from bokeh.io import output_notebook, curdoc
> from bokeh.transform import factor_cmap
> from bokeh.layouts import column, row
> import pandas as pd
> import numpy as np
> import pyodbc
>
> output_file("gmap.html")
>
> # parameters
> server = 'X.X.X.X\PQR'
> db = 'abc'
>
> # Create the connection
> conn = pyodbc.connect('DRIVER={SQL Server};SERVER=' + server + ';DATABASE=' + db + ';Trusted_Connection=yes')
>
> map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=13)
> p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients", plot_width=1000, plot_height=600)
>
> sql = """
> with CTE AS
> (SELECT
> CR.ClientID, CR.Latitude, CR.Longtitude
> FROM
> Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
> WHERE
> C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
> )
> SELECT
> C.ClientID, C.Latitude, C.Longtitude, CL.Sex
> FROM
> CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
> """
> df = pd.read_sql(sql, conn)
>
>
>
> df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
> df['Sex'] = df['Sex'].astype('str')
>
> map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)
> p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Genderwise", plot_width=1000,
> plot_height=600)
>
> lat = df['Latitude'].tolist()
> lon = df['Longtitude'].tolist()
> sex = df['Sex'].tolist()
>
> source = ColumnDataSource(
> data=dict(latitude=lat,
> longitude=lon,
> gender=sex
> )
> )
>
>
> color_mapper = CategoricalColorMapper(factors=['M', 'F', 'U'], palette=['Red', 'Blue', 'Green'])
>
>
> p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
> fill_color={'field': 'gender', 'transform': color_mapper},
> line_color={'field': 'gender', 'transform': color_mapper})
>
> x = np.linspace(0, 4 * np.pi, 100)
> y = np.sin(x)
>
> p.circle(x, y, legend="Male", color="red")
> p.circle(x, 2 * y, legend="Female", color="Blue")
> p.circle(x, 3 * y, legend="Unknown", color="Green")
>
> def update():
> # query db
> curdoc().clear()
> sql = """
> with CTE AS
> (SELECT
> CR.ClientID, CR.Latitude, CR.Longtitude
> FROM
> Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
> WHERE
> C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
> )
> SELECT
> C.ClientID, C.Latitude, C.Longtitude,
> CASE WHEN age > 0 AND age <= 15 THEN 'Children'
> WHEN age > 15 AND age <= 30 THEN 'Young Adult'
> WHEN age > 30 AND age <= 55 THEN 'Adult'
> WHEN age > 55 THEN 'Senior Citizen'
> END AS 'Age_Group'
> FROM
> CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
> """
> df = pd.read_sql(sql, conn)
>
> df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
> df['Age_Group'] = df['Age_Group'].astype('str')
>
> df['Latitude'].median()
> df['Longtitude'].median()
>
> map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)
>
> p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Age wise",
> plot_width=1000, plot_height=600)
>
> lat = df['Latitude'].tolist()
> lon = df['Longtitude'].tolist()
> age = df['Age_Group'].tolist()
>
> source = ColumnDataSource(
> data=dict(latitude=lat,
> longitude=lon,
> age_Group=age
> )
> )
>
> color_mapper = CategoricalColorMapper(factors=['Children', 'Young Adult', 'Adult', 'Senior Citizen'],
> palette=['Red', 'Blue', 'Green', 'Yellow'])
>
> p.add_tools(LassoSelectTool())
> p.add_tools(ZoomInTool())
> p.add_tools(ZoomOutTool())
>
> p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
> fill_color={'field': 'age_Group', 'transform': color_mapper},
> line_color={'field': 'age_Group', 'transform': color_mapper})
>
> x = np.linspace(0, 4 * np.pi, 100)
> y = np.sin(x)
>
> p.circle(x, y, legend="Children : Age <= 15", color="red")
> p.circle(x, 2 * y, legend="Young Adult : 30 >= Age > 15", color="Blue")
> p.circle(x, 3 * y, legend="Adult : 55 >= Age > 30 ", color="Green")
> p.circle(x, 4 * y, legend="Senior Citizen : Age > 55", color="Yellow")
>
> curdoc().add_root(row(button1, button2))
> curdoc().add_root(column(p))
>
> def update1():
> # query db
> curdoc().clear()
> sql = """
> with CTE AS
> (SELECT
> CR.ClientID, CR.Latitude, CR.Longtitude
> FROM
> Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
> WHERE
> C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
> )
> SELECT
> C.ClientID, C.Latitude, C.Longtitude, CL.Sex
> FROM
> CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
> """
> df = pd.read_sql(sql, conn)
>
> df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
> df['Sex'] = df['Sex'].astype('str')
>
> map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)
> p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Genderwise",
> plot_width=1000,
> plot_height=600)
>
> lat = df['Latitude'].tolist()
> lon = df['Longtitude'].tolist()
> sex = df['Sex'].tolist()
>
> source = ColumnDataSource(
> data=dict(latitude=lat,
> longitude=lon,
> gender=sex
> )
> )
>
>
> color_mapper = CategoricalColorMapper(factors=['M', 'F', 'U'], palette=['Red', 'Blue', 'Green'])
>
> p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
> fill_color={'field': 'gender', 'transform': color_mapper},
> line_color={'field': 'gender', 'transform': color_mapper})
>
> x = np.linspace(0, 4 * np.pi, 100)
> y = np.sin(x)
>
> p.circle(x, y, legend="Male", color="red")
> p.circle(x, 2 * y, legend="Female", color="Blue")
> p.circle(x, 3 * y, legend="Unknown", color="Green")
>
> curdoc().add_root(row(button1, button2))
> curdoc().add_root(column(p))
>
> # add a button widget and configure with the call back
> button1 = Button(label="Gender")
> button2 = Button(label="Age")
>
> button1.on_click(update1)
> button2.on_click(update)
>
> # put the button and plot in a layout and add to the document
>
> curdoc().add_root(row(button1, button2))
> curdoc().add_root(column(p))
>
> Here is my app.py file
>
> from flask import Flask, render_template
> from bokeh.embed import autoload_static
> from bokeh.client import pull_session
>
> #instantiating the flask app
> app = Flask(__name__)
>
> #create the index page function
>
> @app.route("/")
> def index():
> session = pull_session(url="http://localhost:5006/Button_test_update_version2&quot;\)
> bokeh_script = autoload_static(None, url="http://localhost:5006/Button_test_update_version2&quot;, session_id=session.id)
> return render_template("index.html", bokeh_script=bokeh_script)
>
> #run the app
> if __name__ == "_main_":
>
> Here is my index.html file,
> <!DOCTYPE html>
> <html lang="en">
> <head>
> <meta charset="UTF-8">
> <title>ABC Visualization</title>
> <link rel="stylesheet" href={‌{url_for('static', filename='css/main.css')}}>
> </head>
> <body>
> <h1>ABC Visualization</h1>
> <div>
> {‌{bokeh_script|safe}}
> </div>
> </body>
> </html>
>
> Here is my main.css file,
>
> h3{
> color : olive;
> }
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/27d007e3-1222-4795-a6a1-b31506c56cc5%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0947e14a-1f73-46ee-9e26-46fcc489096d%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hey Bryan,
Thanks for your response, but even after doing that the issue still persists.

···

On Friday, 15 June 2018 11:38:15 UTC-7, Bryan Van de ven wrote:

Hi,

You need to pass them explicitly as keywords, not positionally:

    gmap(google_api_key="My Google Maps API Key", map_options=map_options, ...

Bryan

On Jun 15, 2018, at 11:34, anuj nimkar [email protected] wrote:

Hey Bryan,

Yes I had posted this issue on multiple groups, as I have still not been able to resolve this and have kind of hit the wall at this point. I am passing those two values as arguments.
p = gmap(“My Google Maps API Key”, map_options, title=“Resolutions Clients Genderwise”, plot_width=1000,

         plot_height=600)

I’m not sure I understand your answer, but please correct me if I’m misunderstanding.

Thanks!

On Friday, 15 June 2018 11:23:38 UTC-7, Bryan Van de ven wrote:

Yes, see:

    [https://stackoverflow.com/questions/50782293/python-bokeh-google-maps-api-patch-doc-error](https://stackoverflow.com/questions/50782293/python-bokeh-google-maps-api-patch-doc-error)

On Jun 15, 2018, at 11:11, anuj nimkar [email protected] wrote:

Hello,
I’m stuck at a point where I try to integrate my bokeh server app with Flask. I am using the GMapOptions library in bokeh to generate a visualization showing the distribution of my client data across a geographical area. I get the following error when I run the Flask app code,

TypeError: init() missing 2 required positional arguments: ‘google_api_key’ and ‘map_options’

I get the same message in the command prompt when I run the bokeh server app independently in the command prompt using the bokeh serve command, but the app runs nevertheless.

Here is my code for the visualization,

coding: utf-8

In[1]:

from bokeh.plotting import figure, output_file, show, gmap
from bokeh.models import *
from bokeh.io import output_notebook, curdoc
from bokeh.transform import factor_cmap
from bokeh.layouts import column, row
import pandas as pd
import numpy as np
import pyodbc

output_file(“gmap.html”)

parameters

server = ‘X.X.X.X\PQR’
db = ‘abc’

Create the connection

conn = pyodbc.connect(‘DRIVER={SQL Server};SERVER=’ + server + ‘;DATABASE=’ + db + ‘;Trusted_Connection=yes’)

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type=“roadmap”, zoom=13)
p = gmap(“My Google Maps API Key”, map_options, title=“Resolutions Clients”, plot_width=1000, plot_height=600)

sql = “”"
with CTE AS
(SELECT
CR.ClientID, CR.Latitude, CR.Longtitude
FROM
Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
WHERE
C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
)
SELECT
C.ClientID, C.Latitude, C.Longtitude, CL.Sex
FROM
CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
“”"
df = pd.read_sql(sql, conn)

df[[‘Latitude’, ‘Longtitude’]] = df[[‘Latitude’, ‘Longtitude’]].apply(pd.to_numeric)
df[‘Sex’] = df[‘Sex’].astype(‘str’)

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type=“roadmap”, zoom=10)
p = gmap(“My Google Maps API Key”, map_options, title=“Resolutions Clients Genderwise”, plot_width=1000,
plot_height=600)

lat = df[‘Latitude’].tolist()
lon = df[‘Longtitude’].tolist()
sex = df[‘Sex’].tolist()

source = ColumnDataSource(
data=dict(latitude=lat,
longitude=lon,
gender=sex
)
)

color_mapper = CategoricalColorMapper(factors=[‘M’, ‘F’, ‘U’], palette=[‘Red’, ‘Blue’, ‘Green’])

p.circle(x=“longitude”, y=“latitude”, size=4, fill_alpha=0.9, source=source,
fill_color={‘field’: ‘gender’, ‘transform’: color_mapper},
line_color={‘field’: ‘gender’, ‘transform’: color_mapper})

x = np.linspace(0, 4 * np.pi, 100)
y = np.sin(x)

p.circle(x, y, legend=“Male”, color=“red”)
p.circle(x, 2 * y, legend=“Female”, color=“Blue”)
p.circle(x, 3 * y, legend=“Unknown”, color=“Green”)

def update():
# query db
curdoc().clear()
sql = “”"
with CTE AS
(SELECT
CR.ClientID, CR.Latitude, CR.Longtitude
FROM
Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
WHERE
C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
)
SELECT
C.ClientID, C.Latitude, C.Longtitude,
CASE WHEN age > 0 AND age <= 15 THEN ‘Children’
WHEN age > 15 AND age <= 30 THEN ‘Young Adult’
WHEN age > 30 AND age <= 55 THEN ‘Adult’
WHEN age > 55 THEN ‘Senior Citizen’
END AS ‘Age_Group’
FROM
CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
“”"
df = pd.read_sql(sql, conn)

df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
df['Age_Group'] = df['Age_Group'].astype('str')

df['Latitude'].median()
df['Longtitude'].median()

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)

p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Age wise",
         plot_width=1000, plot_height=600)

lat = df['Latitude'].tolist()
lon = df['Longtitude'].tolist()
age = df['Age_Group'].tolist()

source = ColumnDataSource(
    data=dict(latitude=lat,
              longitude=lon,
              age_Group=age
              )
)

color_mapper = CategoricalColorMapper(factors=['Children', 'Young Adult', 'Adult', 'Senior Citizen'],
                                      palette=['Red', 'Blue', 'Green', 'Yellow'])

p.add_tools(LassoSelectTool())
p.add_tools(ZoomInTool())
p.add_tools(ZoomOutTool())

p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
         fill_color={'field': 'age_Group', 'transform': color_mapper},
         line_color={'field': 'age_Group', 'transform': color_mapper})

x = np.linspace(0, 4 * np.pi, 100)
y = np.sin(x)

p.circle(x, y, legend="Children : Age <= 15", color="red")
p.circle(x, 2 * y, legend="Young Adult : 30 >= Age > 15", color="Blue")
p.circle(x, 3 * y, legend="Adult : 55 >= Age > 30 ", color="Green")
p.circle(x, 4 * y, legend="Senior Citizen : Age > 55", color="Yellow")

curdoc().add_root(row(button1, button2))
curdoc().add_root(column(p))

def update1():
# query db
curdoc().clear()
sql = “”"
with CTE AS
(SELECT
CR.ClientID, CR.Latitude, CR.Longtitude
FROM
Company C LEFT JOIN ClientRegistration CR on C.CompanyID = CR.CompanyID
WHERE
C.CompanyID = 555 AND (CR.Latitude IS NOT NULL AND CR.Longtitude IS NOT NULL)
)
SELECT
C.ClientID, C.Latitude, C.Longtitude, CL.Sex
FROM
CTE C LEFT JOIN Clients CL on C.ClientID = CL.ClientID
“”"
df = pd.read_sql(sql, conn)

df[['Latitude', 'Longtitude']] = df[['Latitude', 'Longtitude']].apply(pd.to_numeric)
df['Sex'] = df['Sex'].astype('str')

map_options = GMapOptions(lat=37.686293, lng=-97.3614409, map_type="roadmap", zoom=10)
p = gmap("My Google Maps API Key", map_options, title="Resolutions Clients Genderwise",
         plot_width=1000,
         plot_height=600)

lat = df['Latitude'].tolist()
lon = df['Longtitude'].tolist()
sex = df['Sex'].tolist()

source = ColumnDataSource(
    data=dict(latitude=lat,
              longitude=lon,
              gender=sex
              )
)


color_mapper = CategoricalColorMapper(factors=['M', 'F', 'U'], palette=['Red', 'Blue', 'Green'])

p.circle(x="longitude", y="latitude", size=4, fill_alpha=0.9, source=source,
         fill_color={'field': 'gender', 'transform': color_mapper},
         line_color={'field': 'gender', 'transform': color_mapper})

x = np.linspace(0, 4 * np.pi, 100)
y = np.sin(x)

p.circle(x, y, legend="Male", color="red")
p.circle(x, 2 * y, legend="Female", color="Blue")
p.circle(x, 3 * y, legend="Unknown", color="Green")

curdoc().add_root(row(button1, button2))
curdoc().add_root(column(p))

add a button widget and configure with the call back

button1 = Button(label=“Gender”)
button2 = Button(label=“Age”)

button1.on_click(update1)
button2.on_click(update)

put the button and plot in a layout and add to the document

curdoc().add_root(row(button1, button2))
curdoc().add_root(column(p))

Here is my app.py file

from flask import Flask, render_template
from bokeh.embed import autoload_static
from bokeh.client import pull_session

#instantiating the flask app
app = Flask(name)

#create the index page function

@app.route(“/”)
def index():
session = pull_session(url=“http://localhost:5006/Button_test_update_version2”)
bokeh_script = autoload_static(None, url=“http://localhost:5006/Button_test_update_version2”, session_id=session.id)
return render_template(“index.html”, bokeh_script=bokeh_script)

#run the app
if name == “main”:

Here is my index.html file,

ABC Visualization

ABC Visualization

{‌{bokeh_script|safe}}

Here is my main.css file,

h3{
color : olive;
}


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/27d007e3-1222-4795-a6a1-b31506c56cc5%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0947e14a-1f73-46ee-9e26-46fcc489096d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Anuj,

Give it a try using:

from bokeh.models import GMapPlot

plot = GMapPlot(map_options=map_options, api_key=api_key, … )

``

For whatever reason this works for me whereas using ‘gmap’ doesn’t.

Jack

Thanks, Jack! I’ll try GMapPlot out.

···

On Sat, Jun 16, 2018 at 1:05 PM Jack Beanland [email protected] wrote:

Hi Anuj,

Give it a try using:

from bokeh.models import GMapPlot

plot = GMapPlot(map_options=map_options, api_key=api_key, … )

``

For whatever reason this works for me whereas using ‘gmap’ doesn’t.

Jack

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/30098511-79f5-47a3-99f8-9ae85ff75740%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thanks for the GMapPlot suggestion Jack, I don’t get the error by using GMapPlot, but by using GMapPlot I’m having to change my code at several places which I guess is because of the syntax. I’m having a hard time trying to create Legends for my plot. I tried out a few suggestions on stackoverflow but none some to work for me. Have you implemented Legends in your GMapPlot code? If so can you share your code?

Thanks,

Anuj

···

On Saturday, 16 June 2018 16:37:18 UTC-7, anuj nimkar wrote:

Thanks, Jack! I’ll try GMapPlot out.

On Sat, Jun 16, 2018 at 1:05 PM Jack Beanland [email protected] wrote:

Hi Anuj,

Give it a try using:

from bokeh.models import GMapPlot

plot = GMapPlot(map_options=map_options, api_key=api_key, … )

``

For whatever reason this works for me whereas using ‘gmap’ doesn’t.

Jack

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/30098511-79f5-47a3-99f8-9ae85ff75740%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

The issue with gmap was fixed in Bryanv/7985 gmap pos args by bryevdv · Pull Request #7998 · bokeh/bokeh · GitHub

Bryan

···

On Jun 18, 2018, at 15:08, anuj nimkar <[email protected]> wrote:

Thanks for the GMapPlot suggestion Jack, I don't get the error by using GMapPlot, but by using GMapPlot I'm having to change my code at several places which I guess is because of the syntax. I'm having a hard time trying to create Legends for my plot. I tried out a few suggestions on stackoverflow but none some to work for me. Have you implemented Legends in your GMapPlot code? If so can you share your code?

Thanks,
Anuj

On Saturday, 16 June 2018 16:37:18 UTC-7, anuj nimkar wrote:
Thanks, Jack! I’ll try GMapPlot out.

On Sat, Jun 16, 2018 at 1:05 PM Jack Beanland <[email protected]> wrote:
Hi Anuj,

Give it a try using:
from bokeh.models import GMapPlot

......

plot = GMapPlot(map_options=map_options, api_key=api_key, ..... )

For whatever reason this works for me whereas using 'gmap' doesn't.

Jack

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/30098511-79f5-47a3-99f8-9ae85ff75740%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/4e126d25-722d-4c87-9390-6f2e7505f957%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks Bryan!

···

On Mon, Jun 18, 2018 at 3:29 PM, Bryan Van de ven [email protected] wrote:

The issue with gmap was fixed in https://github.com/bokeh/bokeh/pull/7998

Bryan

On Jun 18, 2018, at 15:08, anuj nimkar [email protected] wrote:

Thanks for the GMapPlot suggestion Jack, I don’t get the error by using GMapPlot, but by using GMapPlot I’m having to change my code at several places which I guess is because of the syntax. I’m having a hard time trying to create Legends for my plot. I tried out a few suggestions on stackoverflow but none some to work for me. Have you implemented Legends in your GMapPlot code? If so can you share your code?

Thanks,

Anuj

On Saturday, 16 June 2018 16:37:18 UTC-7, anuj nimkar wrote:

Thanks, Jack! I’ll try GMapPlot out.

On Sat, Jun 16, 2018 at 1:05 PM Jack Beanland [email protected] wrote:

Hi Anuj,

Give it a try using:

from bokeh.models import GMapPlot

plot = GMapPlot(map_options=map_options, api_key=api_key, … )

For whatever reason this works for me whereas using ‘gmap’ doesn’t.

Jack

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/30098511-79f5-47a3-99f8-9ae85ff75740%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/4e126d25-722d-4c87-9390-6f2e7505f957%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/C0972C6A-1726-4817-B9D6-B45FFD30E8AB%40anaconda.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.