How can I change the database bokeh is getting data from while bokeh serve is running? In case my Django app allows a user to select data from a different database.
I am using Django framework, MongoDB, tweeter streaming API and bokeh, I can stream the data just fine using “ColumnDataSource.patch()”, it works exactly how I want it. But for now, I have to start bokeh server on a different terminal, Django on a different terminal, and streaming script on a different terminal for them to work correctly.
The bigger issue is Users can select a topic and I have to visualize it with Bokeh using a database with a topic of interest, currently, I use “bokeh serve --allow-websocket-origin=127.0.0.1:8000 Severe.py” to run the server and I use pull_session and autoload_server to redirect to that Bokeh app.
How can I change the database bokeh is getting data from while bokeh serve is running? In case my Django app allows a user to select data from a different database.
I am using Django framework, MongoDB, tweeter streaming API and bokeh, I can stream the data just fine using “ColumnDataSource.patch()”, it works exactly how I want it. But for now, I have to start bokeh server on a different terminal, Django on a different terminal, and streaming script on a different terminal for them to work correctly.
The bigger issue is Users can select a topic and I have to visualize it with Bokeh using a database with a topic of interest, currently, I use “bokeh serve --allow-websocket-origin=127.0.0.1:8000 Severe.py” to run the server and I use pull_session and autoload_server to redirect to that Bokeh app.
I think you either have to have a single Bokeh instance and speak with it via some kind of RPC (e.g. a queue in a Redis instance) or to provide different ports for different instances.
I guess the second approach makes more sense since it’s easier to implement and you don’t show Bokeh port to your users.
Eugene
···
On Tuesday, September 26, 2017 at 11:36:48 PM UTC+7, kiluvya wrote:
How can I change the database bokeh is getting data from while bokeh serve is running? In case my Django app allows a user to select data from a different database.
I am using Django framework, MongoDB, tweeter streaming API and bokeh, I can stream the data just fine using “ColumnDataSource.patch()”, it works exactly how I want it. But for now, I have to start bokeh server on a different terminal, Django on a different terminal, and streaming script on a different terminal for them to work correctly.
The bigger issue is Users can select a topic and I have to visualize it with Bokeh using a database with a topic of interest, currently, I use “bokeh serve --allow-websocket-origin=127.0.0.1:8000 Severe.py” to run the server and I use pull_session and autoload_server to redirect to that Bokeh app.
How can I change the database bokeh is getting data from while bokeh serve is running? In case my Django app allows a user to select data from a different database.
I am using Django framework, MongoDB, tweeter streaming API and bokeh, I can stream the data just fine using “ColumnDataSource.patch()”, it works exactly how I want it. But for now, I have to start bokeh server on a different terminal, Django on a different terminal, and streaming script on a different terminal for them to work correctly.
The bigger issue is Users can select a topic and I have to visualize it with Bokeh using a database with a topic of interest, currently, I use “bokeh serve --allow-websocket-origin=127.0.0.1:8000 Severe.py” to run the server and I use pull_session and autoload_server to redirect to that Bokeh app.
How can I do that? I have this code in my app after trying to use client sessions. By the way, I am using patch because it is a map
from bokeh.client import pull_session, push_session
session = push_session(curdoc())
def get_patch(): #getting new patches
I started my server with “bokeh serve”, and now when I try to access the “http://localhost:5006/Servere” from my browser, I get error 404. from Django nothing shows.
My knowledge of sessions is not adequate, what am I doing wrong?
···
On Tuesday, September 26, 2017 at 11:48:53 AM UTC-5, Eugene Pakhomov wrote:
What prevents you from creating different sessions from the same Bokeh instance? If you don’t use global state, everything should be fine.
Eugene
On Tuesday, September 26, 2017 at 11:44:26 PM UTC+7, Sebastian Maurice wrote:
Hi
If this could be done it would also help me. But as far as i know you cannot…multiple users on the same session will share the same Bokeh state.
You will likely have to use a reverse proxy for multiple Bokeh users with different topics.
How can I change the database bokeh is getting data from while bokeh serve is running? In case my Django app allows a user to select data from a different database.
I am using Django framework, MongoDB, tweeter streaming API and bokeh, I can stream the data just fine using “ColumnDataSource.patch()”, it works exactly how I want it. But for now, I have to start bokeh server on a different terminal, Django on a different terminal, and streaming script on a different terminal for them to work correctly.
The bigger issue is Users can select a topic and I have to visualize it with Bokeh using a database with a topic of interest, currently, I use “bokeh serve --allow-websocket-origin=127.0.0.1:8000 Severe.py” to run the server and I use pull_session and autoload_server to redirect to that Bokeh app.
As far as I understood your problem in the initial post, you have multiple MongoDB databases where each DB is used by a different Django instance.
Since you use Bokeh inside Django, you’ll have to provide a different port to Bokeh each time you start Django process. You already should be doing so for Django since two applications can’t both be listening to the same port. So just use the same mechanism for Bokeh, where you provide port 5006.
Or did I misunderstood your problem?
Eugene
···
On Wednesday, September 27, 2017 at 12:45:36 AM UTC+7, kiluvya wrote:
Eugene:
How can I do that? I have this code in my app after trying to use client sessions. By the way, I am using patch because it is a map
from bokeh.client import pull_session, push_session
session = push_session(curdoc())
def get_patch(): #getting new patches
I started my server with “bokeh serve”, and now when I try to access the “http://localhost:5006/Servere” from my browser, I get error 404. from Django nothing shows.
My knowledge of sessions is not adequate, what am I doing wrong?
On Tuesday, September 26, 2017 at 11:48:53 AM UTC-5, Eugene Pakhomov wrote:
What prevents you from creating different sessions from the same Bokeh instance? If you don’t use global state, everything should be fine.
Eugene
On Tuesday, September 26, 2017 at 11:44:26 PM UTC+7, Sebastian Maurice wrote:
Hi
If this could be done it would also help me. But as far as i know you cannot…multiple users on the same session will share the same Bokeh state.
You will likely have to use a reverse proxy for multiple Bokeh users with different topics.
How can I change the database bokeh is getting data from while bokeh serve is running? In case my Django app allows a user to select data from a different database.
I am using Django framework, MongoDB, tweeter streaming API and bokeh, I can stream the data just fine using “ColumnDataSource.patch()”, it works exactly how I want it. But for now, I have to start bokeh server on a different terminal, Django on a different terminal, and streaming script on a different terminal for them to work correctly.
The bigger issue is Users can select a topic and I have to visualize it with Bokeh using a database with a topic of interest, currently, I use “bokeh serve --allow-websocket-origin=127.0.0.1:8000 Severe.py” to run the server and I use pull_session and autoload_server to redirect to that Bokeh app.
I can't really comment at length because I am at a conference all week on a demo account and have limited use of my normal laptop. But I wanted to make a few comments.
* using "push_session" to create sessions on a Bokeh server that you then run "outside" the bokeh server by updating with with "session.loop_until_closed()" is a very bad anti-pattern. Recent versions of Bokeh will warn with 10 foot high letters that this is 100% not advised for any "real" usage.
* Instead, you should create a real app that runs inside the Bokeh server, i.e. "bokeh serve app.py" or "bokeh serve app_dir/"
* If you need to, you can use pull_session to create a new session, and customize it before sending it to your users. Here is a small but complete example:
from flask import Flask, render_template
from bokeh.client import pull_session
from bokeh.embed import server_session
* However, even this is often not necessary. You can pass HTML request arguments to "server_session", and this is often an even easier way to customize sessions. E.g. you might pass some HTML args that specify what database to connect to on an per-request basis.
* please note autoload_server is deprecated, it has been split into two simpler functions, server_document and server_session
Thanks,
Bryan
···
On Sep 26, 2017, at 13:50, Eugene Pakhomov <[email protected]> wrote:
My response regarding sessions was to Sebastian.
As far as I understood your problem in the initial post, you have multiple MongoDB databases where each DB is used by a different Django instance.
Since you use Bokeh inside Django, you'll have to provide a different port to Bokeh each time you start Django process. You already should be doing so for Django since two applications can't both be listening to the same port. So just use the same mechanism for Bokeh, where you provide port 5006.
Or did I misunderstood your problem?
Eugene
On Wednesday, September 27, 2017 at 12:45:36 AM UTC+7, kiluvya wrote:
Eugene:
How can I do that? I have this code in my app after trying to use client sessions. By the way, I am using patch because it is a map
from bokeh.client import pull_session, push_session
session = push_session(curdoc())
def get_patch(): #getting new patches
I started my server with "bokeh serve", and now when I try to access the "http://localhost:5006/Servere" from my browser, I get error 404. from Django nothing shows.
My knowledge of sessions is not adequate, what am I doing wrong?
On Tuesday, September 26, 2017 at 11:48:53 AM UTC-5, Eugene Pakhomov wrote:
What prevents you from creating different sessions from the same Bokeh instance? If you don't use global state, everything should be fine.
Eugene
On Tuesday, September 26, 2017 at 11:44:26 PM UTC+7, Sebastian Maurice wrote:
Hi
If this could be done it would also help me. But as far as i know you cannot...multiple users on the same session will share the same Bokeh state.
You will likely have to use a reverse proxy for multiple Bokeh users with different topics.
On Sep 26, 2017 12:36 PM, "kiluvya" <[email protected]> wrote:
How can I change the database bokeh is getting data from while bokeh serve is running? In case my Django app allows a user to select data from a different database.
I am using Django framework, MongoDB, tweeter streaming API and bokeh, I can stream the data just fine using "ColumnDataSource.patch()", it works exactly how I want it. But for now, I have to start bokeh server on a different terminal, Django on a different terminal, and streaming script on a different terminal for them to work correctly.
The bigger issue is Users can select a topic and I have to visualize it with Bokeh using a database with a topic of interest, currently, I use "bokeh serve --allow-websocket-origin=127.0.0.1:8000 Severe.py" to run the server and I use pull_session and autoload_server to redirect to that Bokeh app.
Also, I can parse the name of database like bokeh serve --allow-websocket-origin=127.0.0.1:8000 Severe.py args --name_of_db
but the new connection will be denied because there is bokeh server running already
Remember, multiple users can select two topics and I have to stream them all.
def home(request):
if request.method == ‘POST’:
form = NameForm(request.POST) # A form bound to the POST data
if form.is_valid():
search_value = form.cleaned_data[‘search’]
…#cleaning code
search_value = search_value[0].upper() + search_value[1:] #mongoDB collection name. "db[search_value].find()
#???
file_request = file_html(models, resources)
return(request, file_request)
else:
form = NameForm()
return render(request, u'home.html', {'form': form})
``
But I am having trouble understanding how to pass the “model”.
Here is my bokeh app so far which can run by its own perfectly
from future import unicode_literals, print_function
``
import io
import os
import sys
import numpy
from bokeh.resources import CDN
from bokeh.embed import components, autoload_server, server_session
with io.open(“animated.html”, mode=‘w+’, encoding=‘utf-8’) as f:
f.write(html)
def get_patch():
global states_rates
global state_xs
global state_ys
global state_names
result = collection.find()
temp = []
index_to_patch = []
for each in result:
temp.append(float(each["total_sentiment"]) / each["total"] *100)
for i in range(len(state_names)):
if states_rates[i] != temp[i]:
index_to_patch.append(i)
xs_ = []
ys_ = []
name_ = []
rate_ = []
for each in index_to_patch:
xs_.append((each,state_xs[each]))
ys_.append((each,state_ys[each]))
name_.append((each,state_names[each]))
rate_.append((each,states_rates[each]))
data = { "x" : xs_,
"y" : ys_,
"name" : name_,
"rate" : rate_
}
states_rates = temp
return data
How can I accomplish what you said using HTML request? Or a link to an example
···
On Tuesday, September 26, 2017 at 1:32:57 PM UTC-5, Bryan Van de ven wrote:
Hi,
I can’t really comment at length because I am at a conference all week on a demo account and have limited use of my normal laptop. But I wanted to make a few comments.
using “push_session” to create sessions on a Bokeh server that you then run “outside” the bokeh server by updating with with “session.loop_until_closed()” is a very bad anti-pattern. Recent versions of Bokeh will warn with 10 foot high letters that this is 100% not advised for any “real” usage.
Instead, you should create a real app that runs inside the Bokeh server, i.e. “bokeh serve app.py” or “bokeh serve app_dir/”
If you need to, you can use pull_session to create a new session, and customize it before sending it to your users. Here is a small but complete example:
However, even this is often not necessary. You can pass HTML request arguments to “server_session”, and this is often an even easier way to customize sessions. E.g. you might pass some HTML args that specify what database to connect to on an per-request basis.
please note autoload_server is deprecated, it has been split into two simpler functions, server_document and server_session
As far as I understood your problem in the initial post, you have multiple MongoDB databases where each DB is used by a different Django instance.
Since you use Bokeh inside Django, you’ll have to provide a different port to Bokeh each time you start Django process. You already should be doing so for Django since two applications can’t both be listening to the same port. So just use the same mechanism for Bokeh, where you provide port 5006.
Or did I misunderstood your problem?
Eugene
On Wednesday, September 27, 2017 at 12:45:36 AM UTC+7, kiluvya wrote:
Eugene:
How can I do that? I have this code in my app after trying to use client sessions. By the way, I am using patch because it is a map
from bokeh.client import pull_session, push_session
session = push_session(curdoc())
def get_patch():
#getting new patches
def update():
new_data = get_patch()
source.patch(new_data)
#print(source.data)
curdoc().add_root(p)
curdoc().add_periodic_callback(update, 10000)
session.loop_until_closed()
I started my server with “bokeh serve”, and now when I try to access the “http://localhost:5006/Servere” from my browser, I get error 404. from Django nothing shows.
My knowledge of sessions is not adequate, what am I doing wrong?
On Tuesday, September 26, 2017 at 11:48:53 AM UTC-5, Eugene Pakhomov wrote:
What prevents you from creating different sessions from the same Bokeh instance? If you don’t use global state, everything should be fine.
Eugene
On Tuesday, September 26, 2017 at 11:44:26 PM UTC+7, Sebastian Maurice wrote:
Hi
If this could be done it would also help me. But as far as i know you cannot…multiple users on the same session will share the same Bokeh state.
You will likely have to use a reverse proxy for multiple Bokeh users with different topics.
How can I change the database bokeh is getting data from while bokeh serve is running? In case my Django app allows a user to select data from a different database.
I am using Django framework, MongoDB, tweeter streaming API and bokeh, I can stream the data just fine using “ColumnDataSource.patch()”, it works exactly how I want it. But for now, I have to start bokeh server on a different terminal, Django on a different terminal, and streaming script on a different terminal for them to work correctly.
The bigger issue is Users can select a topic and I have to visualize it with Bokeh using a database with a topic of interest, currently, I use “bokeh serve --allow-websocket-origin=127.0.0.1:8000 Severe.py” to run the server and I use pull_session and autoload_server to redirect to that Bokeh app.