示例#1
0
def get_event_plot():
    """
    Connects the frontend to the Bokeh Server by pulling and
    returning a sesssion which generates Bokeh plots displaying
    all the events for a given run

    Returns:
        str: A script tag that embeds content from a specific 
        existing session on a Bokeh server.
    """
    if request.is_json:
        token = request.args.get("token")
        req = request.get_json()
        run_id = None
        user = None
        try:
            run_id = req["run_id"]
            user = req["user"]
        except:
            return make_response(jsonify({"error": "Bad Request"}), 400)
        if not authenticate(user, token):
            return make_response(jsonify({"error": "Unauthorized API request"}), 403)
        print("RUN ID IS: ", run_id)
        threading.Thread(target=cache_events_request, args=[run_id]).start()
        session_id = generate_session_id()
        my_sessions.insert_one({session_id: run_id})
        script = server_session(url=BOKEH_SERVER_URL, session_id=session_id)
        # use the script in the rendered page
        return script
    else:
        return make_response(jsonify({"error": "Bad Request"}), 400)
示例#2
0
def bokeh_plugin(analysis_name):
    session_url = "http://localhost:5006/" + analysis_name
    # generate a script to load the customized session
    script = server_session(session_id='test_session_id', url=session_url)

    # use the script in the rendered page
    return render_template("analysis_tabbed_bokeh.html", script=script, template="Flask")
示例#3
0
def index():
    with pull_session(url="http://localhost:5006/") as session:
        # generate a script to load the customized session
        script = server_session(session_id=session.id,
                                url='http://localhost:5006')
        # use the script in the rendered page
    return render_template("index.html", script=script, template="Flask")
示例#4
0
def decoders():
    with pull_session(url=decoders_url) as session:
        script = server_session(session_id=session.id, url=decoders_url)

        return render_template("decoders.html",
                               script=script,
                               template="Flask")
示例#5
0
def data_advance(request):

    session = pull_session(url="http://139.196.84.157:8080/offline1")
    script = server_session(None,
                            url="http://139.196.84.157:8080/offline1",
                            session_id=session.id)
    return render(request, 'data_advance.html', {'script': script})
示例#6
0
def bkapp_page():
    # script = server_document('http://localhost:5006/myapp')
    # return render_template("embed.html", script=script, template="Flask")

    name = request.args.get("app") if 'app' in request.args else 'myapp'

    with pull_session(session_id='1234567890',
                      url="http://localhost:5006/" + name) as session:
        session.request_server_info()
        # update or customize that session
        # session.document.roots[0].children[1].title.text = "Special Sliders For A Specific User!"
        # generate a script to load the customized session

        cur_doc = session.document
        button_bokeh = Button(label="Custom Style: Bokeh Button",
                              css_classes=['custom_button_bokeh'])
        cur_doc.add_root(button_bokeh)

        script = server_session(session_id=session.id,
                                url='http://localhost:5006/' + name)
        # use the script in the rendered page
        template_file = "embed.html"
        if name == 'dash':
            template_file = "index.html"
        # page_source = server_html_page_for_session(session, resources=None, title='测试', template=template_file, template_variables=None)
        # page_source = page_source.replace('root.Bokeh.embed.embed_items(docs_json, render_items)', "root.Bokeh.embed.embed_items(docs_json, render_items, '/dash', 'http://localhost:5006/dash')" )
        page_source = render_template(template_file,
                                      script=script,
                                      template="Flask")
        return page_source
示例#7
0
def plojo_help():
    root = urlparse(request.base_url).hostname
    script = server_session(url='http://' + root + ':5006/plojo_help',
                            session_id=generate_session_id())
    return render_template('apps/simuojo.html',
                           script=script,
                           title='Plojo Help')
示例#8
0
def sliders_view(request):
    # Define bokeh endpoint url
    bokeh_server_url = "%sbokehproxy/sliders" % (request.build_absolute_uri(
        location='/'))

    # Generate bokeh session token so user can access plot, this is done for all logged in users per the @login_required decorator
    # ensuring only logged in users can view plots

    # Using newer bokeh server_session method vs.  deprecated bokeh.embed.autoload_server
    # Note: session_id.generate_session_id() relies on the presence of BOKEH_SECRET_KEY defined in settings.py via an OS variable
    server_script = server_session(None,
                                   session_id=session_id.generate_session_id(),
                                   url=bokeh_server_url)

    # Tip: More elaborate permission checks can be made using Django's user system, to generate (or not) bokeh session accesss tokens:
    # if user.is_authenticated() and user.has_perm("bokehdash.change_plot"):
    #     server_session(None, session_id=....)
    # else:
    #     HttpResponseRedirect("You can't see this plot")
    # Tip2: More elaborate permissions checks can also be made with other method decorators @user_passes_test, @permission_required
    # (besides @login_reqired)

    # Proceed with context and response
    context = {
        "graphname": "Sliders",
        "server_script": server_script,
    }
    return render(request, 'bokehdash/bokeh_server.html', context)
示例#9
0
    def getDataLoaderModule(request, editMode=True):
        template = None
        endPoint = 'studio-pipeline/dataloader/'
        # on récupère l'url de l'application du Board du serveur Bokeh
        bokeh_server_url = "%s" % (request.build_absolute_uri(
            location='/')) + endPoint

        session_id = request.COOKIES.get('session_id')
        if session_id == None:
            session_id = token.generate_session_id()

        headers = request.headers
        headers = dict(headers) if headers else {}

        headers['session'] = request.COOKIES.get('crsftoken')

        server_script = server_session(None,
                                       session_id=session_id,
                                       url=bokeh_server_url,
                                       headers=headers)

        # Création du context pour le template Jinja
        context = {"dataloader": server_script}

        template = render(request, 'data/data_loader.html', context)
        return template
示例#10
0
def interlingua():
    with pull_session(url=interlingua_url) as session:
        script = server_session(session_id=session.id, url=interlingua_url)

        return render_template("interlingua.html",
                               script=script,
                               template="Flask")
示例#11
0
 def preview_script(self, request: Request, pk: int = None) -> Response:
     arguments = {"scan_id": str(pk)}
     destination_id = request.GET.get("elementId", "bk-plot")
     with pull_session(url=BOKEH_URL, arguments=arguments) as session:
         html = server_session(session_id=session.id, url=BOKEH_URL)
         script = fix_bokeh_script(html, destination_id=destination_id)
     return HttpResponse(script, content_type="text/javascript")
示例#12
0
def bokeh_js_script(relative_urls=True):
    #session = pull_session(self.address)
    #session.document.template_variables['data_path'] = self.data_path
    s_id = session_id.generate_session_id(secret_key=BOKEH_KEY, signed=True)
    return server_session(None,
                          session_id=s_id,
                          url=BOKEH_ADDRESS,
                          relative_urls=relative_urls,
                          resources='default')
示例#13
0
def hello():
    session = pull_session(session_id=None,
                           url='http://localhost:5006/bokeh_plot')
    script = server_session(session_id=session.id,
                            url='http://localhost:5006/bokeh_plot')
    return render_template('htmlbits.html',
                           script=script,
                           js_resources=js_resources,
                           css_resources=css_resources)
示例#14
0
    def bkapp_page(self):
        with pull_session(url="http://localhost:8080/sliders") as session:
            # update or customize that session
            session.document.roots[0].children[1].title.text = "Special Sliders For A Specific User!"

            # generate a script to load the customized session
            script = server_session(session_id=session.id, url='http://localhost:8080/sliders')

            # use the script in the rendered page
            return render_template("embed.html", script=script, template="Flask")
示例#15
0
def data(request):

    session1 = pull_session(url="http://139.196.84.157:8080/realtime1")
    script1 = server_session(None,
                             url="http://139.196.84.157:8080/realtime1",
                             session_id=session1.id)
    session2 = pull_session(url="http://139.196.84.157:8080/realtime2")
    script2 = server_session(None,
                             url="http://139.196.84.157:8080/realtime2",
                             session_id=session2.id)
    session3 = pull_session(url="http://139.196.84.157:8080/realtime3")
    script3 = server_session(None,
                             url="http://139.196.84.157:8080/realtime3",
                             session_id=session3.id)
    return render(request, 'data.html', {
        'script1': script1,
        'script2': script2,
        'script3': script3
    })
示例#16
0
def total_deaths_since_first(request):
    bokeh_server_url = "%sbokehproxy/covid-total-deaths-since-first" % (
        request.build_absolute_uri(location='/'))
    server_script = server_session(None,
                                   session_id=session_id.generate_session_id(),
                                   url=bokeh_server_url)
    context = {
        "server_script": server_script,
    }
    return render(request, 'charts/total-deaths-since-first.html', context)
示例#17
0
def interactive(request):
    #bokeh_script=autoload_server(None,  url="http://localhost:5006/random-generator")
    server_script = server_session(None,
                                   session_id=session_id.generate_session_id(),
                                   url="http://localhost:5006/slider")
    context = {
        "graphname": "Sliders",
        "server_script": server_script,
    }
    return render(request, 'bokehapp/interactive.html', context)
示例#18
0
def daily_confirmed_vs_time(request):
    bokeh_server_url = "%sbokehproxy/covid-daily-confirmed-cases" % (
        request.build_absolute_uri(location='/'))
    server_script = server_session(None,
                                   session_id=session_id.generate_session_id(),
                                   url=bokeh_server_url)
    context = {
        "server_script": server_script,
    }
    return render(request, 'charts/daily-confirmed-cases.html', context)
示例#19
0
def confirmed_against_time_bar(request):
    bokeh_server_url = "%sbokehproxy/covid-confirmed-against-time-bar" % (
        request.build_absolute_uri(location='/'))
    server_script = server_session(None,
                                   session_id=session_id.generate_session_id(),
                                   url=bokeh_server_url)
    context = {
        "server_script": server_script,
    }
    return render(request, 'charts/confirmed-against-time-bar.html', context)
示例#20
0
def confirmed_uk_map_plot(request):
    bokeh_server_url = "%sbokehproxy/covid-confirmed-uk-map-plot" % (
        request.build_absolute_uri(location='/'))
    server_script = server_session(None,
                                   session_id=session_id.generate_session_id(),
                                   url=bokeh_server_url)
    context = {
        "server_script": server_script,
    }
    return render(request, 'charts/confirmed-uk-map-plot.html', context)
示例#21
0
 def plot_script(self, request, *args, **kwargs):
     destination_id = request.GET.get("id", "bk-plot")
     with pull_session(url=BOKEH_URL) as session:
         script = server_session(session_id=session.id, url=BOKEH_URL)
         soup = BeautifulSoup(script, features="lxml")
         element = soup(["script"])[0]
         random_id = element.attrs["id"]
         script = element.contents[0]
         script = script.replace(random_id, destination_id)
     return HttpResponse(script, content_type="text/javascript")
示例#22
0
def country_stats(request):
    bokeh_server_url = "%sbokehproxy/covid-country-stats" % (
        request.build_absolute_uri(location='/'))
    server_script = server_session(None,
                                   session_id=session_id.generate_session_id(),
                                   url=bokeh_server_url)
    context = {
        "server_script": server_script,
    }
    return render(request, 'charts/country-stats.html', context)
示例#23
0
def deaths_vs_time(request):
    bokeh_server_url = "%sbokehproxy/covid-deaths-against-time" % (
        request.build_absolute_uri(location='/'))
    server_script = server_session(None,
                                   session_id=session_id.generate_session_id(),
                                   url=bokeh_server_url)
    context = {
        "server_script": server_script,
    }
    return render(request, 'charts/deaths-against-time.html', context)
示例#24
0
def index():
    index = "home"
    with pull_session(url=BOKEH_URL) as session:
        # generate a script to load the customized session
        script = server_session(session_id=session.id, url=BOKEH_URL)

    return render_template("index.html",
                           script=script,
                           template="Flask",
                           index=index)
示例#25
0
def Test(request):
    bokeh_server_url = "%sbokehproxy/Test" % (request.build_absolute_uri(
        location='/'))
    server_script = server_session(None,
                                   session_id=session_id.generate_session_id(),
                                   url=bokeh_server_url)
    context = {
        "graphname": "Test",
        "server_script": server_script,
    }
    return render(request, 'charts/Test.html', context)
示例#26
0
def histogram_view(request):
    bokeh_server_url = "%sbokehproxy/selection_histogram" % (
        request.build_absolute_uri(location='/'))
    server_script = server_session(None,
                                   session_id=session_id.generate_session_id(),
                                   url=bokeh_server_url)
    context = {
        "graphname": "Selection Histogram",
        "server_script": server_script,
    }
    return render(request, 'bokehdash/bokeh_server.html', context)
示例#27
0
def index():
    # pull new session from running bokeh server
    with pull_session(url=app_url) as session:

        # update or customise that session
        session.document.roots[0].title.text = "Random Generator"

        #Generate a script to load the customised session
        script = server_session(session_id=session.id, url=app_url)

        return render_template("index.html", script = script, template = "Flask")
示例#28
0
def choropleth(request):

    #pull the session from the actively running bokeh app
    app_url = "http://localhost:5600/bokeh_choropleth"

    with pull_session(url=app_url) as session:
        server_script = server_session(session_id=session.id, url=app_url)

    script = server_script

    form = AnalysisForm
    return render(request, 'analysis/analysis.html', {'form': form, 'div': script})
示例#29
0
def bkapp_page(request):
    with pull_session(url="http://localhost:5006/Interactive") as session:
        # update or customize that session
        session.document.roots[0].children[
            1].title.text = "Special Sliders For A Specific User!"

        # generate a script to load the customized session
        script = server_session(session_id=session.id,
                                url="http://localhost:5006/Interactive")

        # use the script in the rendered page
        return render(request, "embed.html", dict(script=script))
示例#30
0
def wik():
    """App route for wik application."""
    if 'auth' in session.keys():
        if session['auth'] == 1:
            script1 = server_session(url=f'{BOKEH_URL}',
                                     session_id=generate_session_id())

            return render_template("app.html",
                                   script1=script1,
                                   relative_urls=True)

    return redirect(f"{WIK_URL}/login")
示例#31
0
def bkapp_page():

    # pull a new session from aunning Bokeh server
    with pull_session(url=app_url) as session:

        # update or customize that session
        session.document.roots[0].title.text = "Special Plot Title For A Specific User!"

        # generate a script to load the customized session
        script = server_session(session_id=session.id, url=app_url)

        # use the script in the rendered page
        return render_template("embed.html", script=script, template="Flask")
示例#32
0
文件: widget.py 项目: alamont/bokeh
    location_select.on_change('value', on_location_change)

    controls = row(children=[year_select, location_select])
    layout = column(children=[controls, pyramid(), population()])

    return layout

layout = create_layout()

update_data()

html = """
<html>
    <head></head>
    <body>
        %s
    </body>
</html>
""" % server_session(layout, session_id=session.id, relative_urls=False)

with io.open("widget.html", mode='w+', encoding='utf-8') as f:
    f.write(html)

print(__doc__)

document.add_root(layout)

if __name__ == "__main__":
    print("\npress ctrl-C to exit")
    session.loop_until_closed()