Esempio n. 1
0
    def __init__(self, worker, io_loop=None, prefix='', **kwargs):
        self.worker = worker
        self.server_kwargs = kwargs
        self.server_kwargs['prefix'] = prefix or None
        prefix = prefix or ''
        prefix = prefix.rstrip('/')
        if prefix and not prefix.startswith('/'):
            prefix = '/' + prefix

        extra = {'prefix': prefix}

        extra.update(template_variables)

        main = Application(FunctionHandler(partial(main_doc, worker, extra)))
        crossfilter = Application(FunctionHandler(partial(crossfilter_doc, worker, extra)))
        systemmonitor = Application(FunctionHandler(partial(systemmonitor_doc, worker, extra)))
        counters = Application(FunctionHandler(partial(counters_doc, worker, extra)))

        self.apps = {'/main': main,
                     '/counters': counters,
                     '/crossfilter': crossfilter,
                     '/system': systemmonitor}

        self.loop = io_loop or worker.loop
        self.server = None
Esempio n. 2
0
    def __init__(self, scheduler, io_loop=None):
        self.scheduler = scheduler
        systemmonitor = Application(
            FunctionHandler(partial(systemmonitor_doc, scheduler)))
        workers = Application(FunctionHandler(partial(workers_doc, scheduler)))

        self.apps = {'/system': systemmonitor, '/workers': workers}

        self.loop = io_loop or scheduler.loop
        self.server = None
Esempio n. 3
0
    def __init__(self, scheduler, io_loop=None, prefix='', **kwargs):
        self.scheduler = scheduler
        prefix = prefix or ''
        prefix = prefix.rstrip('/')
        if prefix and not prefix.startswith('/'):
            prefix = '/' + prefix
        self.prefix = prefix

        self.server_kwargs = kwargs
        self.server_kwargs['prefix'] = prefix or None

        systemmonitor = Application(FunctionHandler(partial(systemmonitor_doc, scheduler, self.extra)))
        workers = Application(FunctionHandler(partial(workers_doc, scheduler, self.extra)))
        stealing = Application(FunctionHandler(partial(stealing_doc, scheduler, self.extra)))
        counters = Application(FunctionHandler(partial(counters_doc, scheduler, self.extra)))
        events = Application(FunctionHandler(partial(events_doc, scheduler, self.extra)))
        tasks = Application(FunctionHandler(partial(tasks_doc, scheduler, self.extra)))
        status = Application(FunctionHandler(partial(status_doc, scheduler, self.extra)))
        profile = Application(FunctionHandler(partial(profile_doc, scheduler, self.extra)))
        graph = Application(FunctionHandler(partial(graph_doc, scheduler, self.extra)))

        self.apps = {
            '/system': systemmonitor,
            '/stealing': stealing,
            '/workers': workers,
            '/events': events,
            '/counters': counters,
            '/tasks': tasks,
            '/status': status,
            '/profile': profile,
            '/graph': graph,
        }

        self.loop = io_loop or scheduler.loop
        self.server = None
Esempio n. 4
0
    def __init__(self, worker, io_loop=None):
        self.worker = worker
        main = Application(FunctionHandler(partial(main_doc, worker)))
        crossfilter = Application(FunctionHandler(partial(crossfilter_doc, worker)))
        systemmonitor = Application(FunctionHandler(partial(systemmonitor_doc, worker)))
        counters = Application(FunctionHandler(partial(counters_doc, worker)))

        self.apps = {'/main': main,
                     '/counters': counters,
                     '/crossfilter': crossfilter,
                     '/system': systemmonitor}

        self.loop = io_loop or worker.loop
        self.server = None
Esempio n. 5
0
def run_dashboard(
    database_paths,
    no_browser,
    port,
    updating_options,
):
    """Start the dashboard pertaining to one or several databases.

    Args:
        database_paths (str or pathlib.Path or list): Path(s) to an sqlite3 file which
            typically has the file extension ``.db``.
        no_browser (bool): If True the dashboard does not open in the browser.
        port (int): Port where to display the dashboard.
        updating_options (dict): Specification how to update the plotting data.
            It contains rollover, update_frequency, update_chunk, jump and stride.

    """
    database_name_to_path = _process_database_paths(database_paths)

    port = _find_free_port() if port is None else port
    port = int(port)

    session_data = _create_session_data(database_name_to_path)

    master_app_func = partial(
        master_app,
        database_name_to_path=database_name_to_path,
        session_data=session_data,
    )
    apps = {"/": Application(FunctionHandler(master_app_func))}

    for database_name in database_name_to_path:
        partialed = partial(
            monitoring_app,
            database_name=database_name,
            session_data=session_data[database_name],
            updating_options=updating_options,
            start_immediately=len(database_name_to_path) == 1,
        )
        apps[f"/{database_name}"] = Application(FunctionHandler(partialed))

    if len(database_name_to_path) == 1:
        path_to_open = f"/{list(database_name_to_path)[0]}"
    else:
        path_to_open = "/"

    _start_server(apps=apps,
                  port=port,
                  no_browser=no_browser,
                  path_to_open=path_to_open)
Esempio n. 6
0
def launch_server():
    """
    Launch a bokeh_server to plot the a timetool time history, timetool amp
    vs ipm, and correlation graph by using zmq to get the data.
    
    """

    context = zmq.Context()

    origins = ["localhost:{}".format(5000)]

    apps = {'/': Application(FunctionHandler(partial(make_document, context)))}
    server = Server(apps, port=5000)

    server.start()

    print('Opening Bokeh application on:')
    for entry in origins:
        print('\thttp://{}/'.format(entry))

    try:
        server.io_loop.start()
    except KeyboardInterrupt:
        print("terminating")
        server.io_loop.stop()
Esempio n. 7
0
def run_server(config=None, path='/', port=5000):
    """Run the bokeh server."""
    makedoc = make_makedoc()
    apps = {path: Application(FunctionHandler(makedoc))}

    server = Server(apps, port=port, allow_websocket_origin=['*'])
    server.run_until_shutdown()
Esempio n. 8
0
def BokehApplication(applications, server, prefix="/", template_variables={}):
    prefix = prefix or ""
    prefix = "/" + prefix.strip("/")
    if not prefix.endswith("/"):
        prefix = prefix + "/"

    extra = toolz.merge({"prefix": prefix}, template_variables)

    apps = {
        k: functools.partial(v, server, extra)
        for k, v in applications.items()
    }
    apps = {k: Application(FunctionHandler(v)) for k, v in apps.items()}
    kwargs = dask.config.get(
        "distributed.scheduler.dashboard.bokeh-application").copy()
    extra_websocket_origins = create_hosts_whitelist(
        kwargs.pop("allow_websocket_origin"), server.http_server.port)

    application = BokehTornado(
        apps,
        prefix=prefix,
        use_index=False,
        extra_websocket_origins=extra_websocket_origins,
        **kwargs,
    )
    return application
Esempio n. 9
0
    def _run_server(fnc_make_document,
                    iplot=True,
                    notebook_url='localhost:8889',
                    port=80,
                    ioloop=None):
        '''
        Runs a Bokeh webserver application. Documents will be created using
        fnc_make_document
        '''

        handler = FunctionHandler(fnc_make_document)
        app = Application(handler)

        if iplot and 'ipykernel' in sys.modules:
            show(app, notebook_url=notebook_url)  # noqa
        else:
            apps = {'/': app}

            print(f'Open your browser here: http://localhost:{port}')
            server = Server(apps, port=port, io_loop=ioloop)
            if ioloop is None:
                server.run_until_shutdown()
            else:
                server.start()
                ioloop.start()
Esempio n. 10
0
 def _normalize(self, obj: ApplicationLike) -> Application:
     if callable(obj):
         return Application(FunctionHandler(obj))
     elif isinstance(obj, Path):
         return build_single_handler_application(obj)
     else:
         return obj
Esempio n. 11
0
def maybe_start_dashboard(experiment, port=5000):
    if DaskperimentBoard._STARTED:
        # do not run duplicatedly
        # shoud find better way...
        return

    from bokeh.application import Application
    from bokeh.application.handlers.function import FunctionHandler
    from bokeh.server.server import Server
    from tornado.web import StaticFileHandler

    h = DaskperimentBoard(experiment)

    apps = {'/': Application(FunctionHandler(h.make_document))}

    STATIC = get_resources('statics')
    patterns = [(r"/statics/(.*)", StaticFileHandler, {"path": STATIC})]

    server = Server(apps, port=port, extra_patterns=patterns)

    if experiment._environment.maybe_jupyter():
        # in jupyter, .run_until_shutdown() may raise RuntimeError
        # because of IOLoop
        server.start()
    else:
        server.run_until_shutdown()

    DaskperimentBoard._STARTED = True
    return server
def run_dashboard(plot_data_path,
                  description_table_path,
                  no_browser=None,
                  port=None):
    """Start the dashboard pertaining to one or several databases.

    Args:
        plot_data_path (str or pathlib.Path): path to the json with the plotting data.
        description_table_path (str or pathlib.Path): path to the description table.
        no_browser (bool, optional): If True the dashboard does not open in the browser.
        port (int, optional): Port where to display the dashboard.

    """
    port = find_free_port() if port is None else int(port)
    no_browser = False if no_browser is None else bool(no_browser)

    with open(plot_data_path, "r") as f:
        plot_data = json.load(f)
    description = pd.read_csv(description_table_path)

    partialed = partial(covid_app,
                        plot_data=plot_data,
                        description=description)
    apps = {"/": Application(FunctionHandler(partialed))}

    _start_server(apps=apps, port=port, no_browser=no_browser)
Esempio n. 13
0
def launch_server(plotName):
    """
    Launch a bokeh_server to plot the correlation of two variables
    vs ipm, and correlation graph by using zmq to get the data.
    
    """

    setupDict = yaml.load(open('smalldata_plot.yml', 'r'))
    plotDict = setupDict[plotName]

    context = zmq.Context()

    hostname = socket.gethostname()
    origins = ["%s:%d" % (hostname, plotDict['port'])]

    apps = {
        '/':
        Application(FunctionHandler(partial(make_document, context, plotName)))
    }
    server = Server(apps, port=plotDict['port'])

    server.start()

    print('Opening Bokeh application on:')
    for entry in origins:
        print('\thttp://{}/'.format(entry))

    try:
        server.io_loop.start()
    except KeyboardInterrupt:
        print("terminating")
        server.io_loop.stop()
Esempio n. 14
0
def run_server(
    cell_stack,
    input_data,
    port=5000,
    markers=None,
    default_umap_marker=None,
    default_cell_marker=None,
    server_kwargs={},
):
    print(server_kwargs)
    apps = {
        "/": Application(
            FunctionHandler(
                partial(
                    prepare_server,
                    cell_stack=cell_stack,
                    input_data=input_data,
                    cell_markers=markers,
                    default_umap_marker=default_umap_marker,
                    default_cell_marker=default_cell_marker,
                )
            )
        )
    }
    server = Server(apps, port=port, **server_kwargs)
    server.run_until_shutdown()
def bk_worker():
    """Start bokeh server on port 5006"""
    server = Server({'/': Application(FunctionHandler(tabs.runServer))},
                    io_loop=IOLoop(),
                    port=5006,
                    allow_websocket_origin=["*"])
    server.start()
    server.io_loop.start()
Esempio n. 16
0
def add_function_handler(id):
    write('Importing module with id ' + id + '\n')
    module = importlib.import_module("plots.plot_" + id)
    make_document = getattr(module, "make_document")
    # invoke make_document to identify runtime errors
    make_document(Document())

    plotDict[id] = Application(FunctionHandler(make_document))
Esempio n. 17
0
    def __init__(self, scheduler, io_loop=None):
        self.scheduler = scheduler
        systemmonitor = Application(
            FunctionHandler(partial(systemmonitor_doc, scheduler)))
        workers = Application(FunctionHandler(partial(workers_doc, scheduler)))
        stealing = Application(
            FunctionHandler(partial(stealing_doc, scheduler)))
        counters = Application(
            FunctionHandler(partial(counters_doc, scheduler)))
        events = Application(FunctionHandler(partial(events_doc, scheduler)))
        tasks = Application(FunctionHandler(partial(tasks_doc, scheduler)))
        status = Application(FunctionHandler(partial(status_doc, scheduler)))

        self.apps = {
            '/system': systemmonitor,
            '/stealing': stealing,
            '/workers': workers,
            '/events': events,
            '/counters': counters,
            '/tasks': tasks,
            '/status': status
        }

        self.loop = io_loop or scheduler.loop
        self.server = None
Esempio n. 18
0
def run_server(filename, config=None, path='/', port=5000):
    """Run the bokeh server."""
    if config is None:
        config = default_config(filename)
    makedoc = make_makedoc(filename, config)
    apps = {path: Application(FunctionHandler(makedoc))}

    server = Server(apps, port=port, allow_websocket_origin=['*'])
    server.run_until_shutdown()
Esempio n. 19
0
def demo_worker():
    # Can't pass num_procs > 1 in this configuration. If you need to run multiple
    # processes, see e.g. flask_gunicorn_embed.py
    apps = {'/demo': Application(FunctionHandler(modify_doc))}
    server = Server(apps, io_loop=IOLoop(), port=5006)
    print("Start the bokeh server:")
    server.start()
    server.io_loop.start()
    return
Esempio n. 20
0
def old_main(_):

    io_loop = IOLoop.current()
    bokeh_app = Application(FunctionHandler(modify_doc))
    server_kwargs = {'port': 8830}
    server = Server({'/': bokeh_app}, io_loop=io_loop, **server_kwargs)

    server.start()

    io_loop.add_callback(server.show, "/")
Esempio n. 21
0
def start_server():
    if combo.get() != "":
        messagebox.showinfo("Info", "Сервер успешно запущен!")
        app = Application(FunctionHandler(flightradar))
        server = Server(app, port=8084)
        webbrowser.get(using="safari").open_new_tab(
            "localhost:8084")  # открытие браузера
        server.run_until_shutdown()
    else:
        messagebox.showerror("Ошибка", "Заполните данные")
Esempio n. 22
0
    def ready(self):

        print("DjangoBokehConfig.ready()")
        os.environ['BOKEH_NODEJS_PATH'] = settings.BOKEH_NODEJS_PATH

        bokeh_app_base_path = os.path.join(settings.BASE_DIR, "djangobokeh",
                                           "bokeh_apps")
        path_list = glob.glob(os.path.join(bokeh_app_base_path, "*.py"))
        print(path_list)

        applications = {}
        for path in path_list:
            application = build_single_handler_application(path)

            route = application.handlers[0].url_path()

            if not route:
                if '/' in applications:
                    raise RuntimeError(
                        "Don't know the URL path to use for %s" % (path))
                route = '/'
            applications[route] = application

        if callable(applications):
            applications = Application(FunctionHandler(applications))

        if isinstance(applications, Application):
            applications = {'/': applications}

        for k, v in list(applications.items()):
            if callable(v):
                applications[k] = Application(FunctionHandler(v))
            if all(not isinstance(handler, DocumentLifecycleHandler)
                   for handler in applications[k]._handlers):
                applications[k].add(DocumentLifecycleHandler())

        self._applications = dict()

        for k, v in applications.items():
            self._applications[k] = ApplicationContext(v, url=k)

        self.routing_config = RoutingConfiguration(self._applications)
 def __init__(self, X, y=None, url="localhost:8888", **kwargs):
     """
     Constructor for the HDVis class.
     """
     self.X, self.y = X, y
     self.features = X.columns.to_numpy()
     self.brushes = []
     self._kwargs = kwargs
     app = Application(FunctionHandler(
         self._make_bokeh_doc))  # make document
     show(app, notebook_url=url)  # show document in notebook
Esempio n. 24
0
 def __init__(self, X, y=None, url="localhost:8888", bin_count=50):
     """
     Constructer for the HistView class.
     """
     # Need to add checks to only plot a fraction of the data if it is large.
     self.X, self.y = X, y
     self.bin_edges = np.linspace(0, 1, bin_count + 1)
     self._are_features_bounded(X)
     app = Application(FunctionHandler(
         self._make_bokeh_doc))  # make document
     show(app, notebook_url=url)  # show document in notebook
Esempio n. 25
0
 def runBokehServer(self):
     """@brief Run the bokeh server. This is a blocking method."""
     apps = {'/': Application(FunctionHandler(self._createPlot))}
     #As this gets run in a thread we need to start an event loop
     evtLoop = asyncio.new_event_loop()
     asyncio.set_event_loop(evtLoop)
     server = Server(apps, port=self._bokehPort)
     server.start()
     #Show the server in a web browser window
     server.io_loop.add_callback(server.show, "/")
     server.io_loop.start()
Esempio n. 26
0
    def __init__(self, simulation):
        self.simulation = simulation
        self.env = self.simulation.env
        self.events = []
        self.not_started = True
        self.start = False
        logger.debug('Opening Bokeh application on http://localhost:5006/')
        apps = {'/': Application(FunctionHandler(self.make_document))}

        self.server = Server(apps, port=8080)
        self.server.start()
Esempio n. 27
0
 def start_io_loop(self, child_conn):
     self.io_loop = IOLoop.current()
     self.server = Server(applications={
         '/' + self.app_name:
         Application(FunctionHandler(self.make_document))
     },
                          io_loop=self.io_loop,
                          port=5001)
     self.server.start()
     self.server.show('/' + self.app_name)
     self.cc = child_conn
     self.io_loop.start()
Esempio n. 28
0
def show(df, port=8080):
    doc_maker = document_factory(df)
    apps = {'/': Application(FunctionHandler(doc_maker))}
    # might need to add allow_websocket_origin=['foo.com', 'localhost', etc]
    server = Server(apps, port=port)

    # bit of a race condition here, but it hasn't bit me yet...
    url = "http://localhost:{}".format(port)
    if BROWSER is not None:
        webbrowser.get(BROWSER).open(url)
    else:
        webbrowser.open(url)
    server.run_until_shutdown()
Esempio n. 29
0
def run_dashboard(database_paths, no_browser=None, port=None):
    """Start the dashboard pertaining to one or several databases.

    Args:
        database_paths (str or pathlib.Path or list): Path(s) to an sqlite3 file which
            typically has the file extension ``.db``. See :ref:`logging` for details.
        no_browser (bool, optional): If True the dashboard does not open in the browser.
        port (int, optional): Port where to display the dashboard.

    """
    database_name_to_path, no_browser, port = _process_dashboard_args(
        database_paths=database_paths, no_browser=no_browser, port=port
    )

    session_data = _create_session_data(database_name_to_path)

    master_app_func = partial(
        master_app,
        database_name_to_path=database_name_to_path,
        session_data=session_data,
    )
    apps = {"/": Application(FunctionHandler(master_app_func))}

    for database_name in database_name_to_path:
        partialed = partial(
            monitoring_app,
            database_name=database_name,
            session_data=session_data[database_name],
        )
        apps[f"/{database_name}"] = Application(FunctionHandler(partialed))

    if len(database_name_to_path) == 1:
        path_to_open = f"/{list(database_name_to_path)[0]}"
    else:
        path_to_open = "/"

    _start_server(
        apps=apps, port=port, no_browser=no_browser, path_to_open=path_to_open
    )
Esempio n. 30
0
def main():
    """Launch the server and connect to it.
    """
    print("Preparing a bokeh application.")
    io_loop = IOLoop.current()
    bokeh_app = Application(FunctionHandler(modify_doc))

    server = Server({"/": bokeh_app}, io_loop=io_loop)
    server.start()
    print("Opening Bokeh application on http://localhost:5006/")

    io_loop.add_callback(server.show, "/")
    io_loop.start()