Exemple #1
0
def test_param_function_pane_update(document, comm):
    test = View()

    objs = {0: HTML("012"), 1: HTML("123")}

    @param.depends(test.param.a)
    def view(a):
        return objs[a]

    pane = Pane(view)
    inner_pane = pane._pane
    assert inner_pane is not objs[0]
    assert inner_pane.object is objs[0].object
    assert pane._internal

    test.a = 1

    assert pane._pane is inner_pane
    assert pane._internal

    objs[0].param.watch(print, ['object'])

    test.a = 0

    assert pane._pane is not inner_pane
    assert not pane._internal
def _fast_button_card():
    button = Button(name="Click me", button_type="primary")
    button.param.name.precedence = 0
    button.param.clicks.precedence = 0
    button.param.disabled.precedence = 0
    button.param.button_type.precedence = 0
    button_parameters = [
        "name",
        "button_type",
        "clicks",
        "disabled",
        "width",
        "height",
        "sizing_mode",
    ]
    settings = Param(
        button,
        parameters=button_parameters,
        show_name=False,
        sizing_mode="stretch_width",
    )
    return Column(
        HTML("<h2>Button</h2>"),
        button,
        HTML("<h3>Parameters</h3>"),
        settings,
        sizing_mode="stretch_both",
    )
Exemple #3
0
def html_server_session():
    html = HTML('<h1>Title</h1>')
    server = html._get_server(port=5006)
    session = pull_session(session_id='Test',
                           url="http://localhost:{:d}/".format(server.port),
                           io_loop=server.io_loop)
    yield html, server, session
    try:
        server.stop()
    except AssertionError:
        pass  # tests may already close this
Exemple #4
0
def test_get_server():
    html = HTML('<h1>Title</h1>')

    server = html.get_server(port=5006)
    assert server.port == 5006

    url = "http://localhost:" + str(server.port) + "/"
    session = pull_session(session_id='Test', url=url, io_loop=server.io_loop)
    root = session.document.roots[0]
    assert isinstance(root, Div)
    assert root.text == '<h1>Title</h1>'
    server.stop()
Exemple #5
0
def test_server_update():
    html = HTML('<h1>Title</h1>')

    server = html._get_server(port=5006)
    url = "http://localhost:" + str(server.port) + "/"
    session = pull_session(session_id='Test', url=url, io_loop=server.io_loop)

    html.object = '<h1>New Title</h1>'

    session.pull()
    root = session.document.roots[0]
    assert isinstance(root, BkHTML)
    assert root.text == '&lt;h1&gt;New Title&lt;/h1&gt;'
    server.stop()
Exemple #6
0
def test_server_change_io_state():
    html = HTML('<h1>Title</h1>')

    server = html.get_server(port=5006)
    url = "http://localhost:" + str(server.port) + "/"
    session = pull_session(session_id='Test', url=url, io_loop=server.io_loop)

    def handle_event(event):
        assert state.curdoc is session.document

    html.param.watch(handle_event, 'object')
    html._server_change(session.document, 'text', '<h1>Title</h1>',
                        '<h1>New Title</h1>')

    server.stop()
Exemple #7
0
def test_console_output_accumulate_stdout(document, comm, get_display_handle):
    pane = HTML()
    model = pane.get_root(document, comm)
    handle = get_display_handle(model)

    pane._on_stdout(model.ref['id'], ['print output'])
    assert handle == {'text/html': 'print output</br>', 'raw': True}

    pane._on_stdout(model.ref['id'], ['new output'])
    assert handle == {'text/html': 'print output</br>\nnew output</br>', 'raw': True}

    pane._cleanup(model)
    assert model.ref['id'] not in state._handles
Exemple #8
0
def test_console_output_replace_stdout(document, comm, get_display_handle):
    pane = HTML()
    with set_env_var('PANEL_CONSOLE_OUTPUT', 'replace'):
        model = pane.get_root(document, comm)
        handle = get_display_handle(model)

        pane._on_stdout(model.ref['id'], ['print output'])
        assert handle == {'text/html': 'print output</br>', 'raw': True}

        pane._on_stdout(model.ref['id'], ['new output'])
        assert handle == {'text/html': 'new output</br>', 'raw': True}

        pane._cleanup(model)
        assert model.ref['id'] not in state._handles
Exemple #9
0
def test_app():
    data = {"x": [1, 2, 3, 4, 5], "y": [3800, 3700, 3800, 3900, 4000]}

    trend = Trend(
        title="Panel Users",
        value=4000,
        value_change=0.51,
        data=data,
        height=200,
        width=200,
    )

    def update_datasource():
        new_x = max(data["x"]) + 1
        old_y = data["y"][-1]
        new_y = random.uniform(-old_y * 0.05, old_y * 0.05) + old_y * 1.01
        trend.stream({"x": [new_x], "y": [new_y]}, rollover=50)

        y_series = data["y"]
        trend.value = y_series[-1]
        change = y_series[-1] / y_series[-2] - 1
        trend.value_change = change

    settings_panel = Param(
        trend,
        parameters=[
            "height",
            "width",
            "sizing_mode",
            "layout",
            "title",
            "plot_color",
            "plot_type",
            "value_change_pos_color",
            "value_change_neg_color",
        ],
        widgets={
            "height": {"widget_type": IntSlider, "start": 0, "end": 800, "step": 1},
            "width": {"widget_type": IntSlider, "start": 0, "end": 800, "step": 1},
        },
        sizing_mode="fixed",
        width=400,
    )
    app = Column(
        HTML(
            "<h1>Panel - Streaming to TrendIndicator<h1>",
            sizing_mode="stretch_width",
            background="black",
            style={"color": "white", "padding": "15px"},
        ),
        Row(WidgetBox(settings_panel), trend, sizing_mode="stretch_both"),
        sizing_mode="stretch_both",
    )
    state.add_periodic_callback(update_datasource, period=50)
    return app
Exemple #10
0
def test_html_pane(document, comm):
    pane = HTML("<h1>Test</h1>")

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    model = row.children[0]
    assert row.ref['id'] in pane._callbacks
    assert pane._models[row.ref['id']] is model
    div = get_div(model)
    assert div.text == "<h1>Test</h1>"

    # Replace Pane.object
    pane.object = "<h2>Test</h2>"
    model = row.children[0]
    assert div is get_div(model)
    assert row.ref['id'] in pane._callbacks
    assert pane._models[row.ref['id']] is model
    assert div.text == "<h2>Test</h2>"

    # Cleanup
    pane._cleanup(row)
    assert pane._callbacks == {}
    assert pane._models == {}
Exemple #11
0
def test_console_output_disable_stdout(document, comm, get_display_handle):
    pane = HTML()
    with set_env_var('PANEL_CONSOLE_OUTPUT', 'disable'):
        model = pane.get_root(document, comm)
        handle = get_display_handle(model)

        pane._on_stdout(model.ref['id'], ['print output'])
        assert handle == {}

        pane._cleanup(model)
        assert model.ref['id'] not in state._handles
Exemple #12
0
def test_card_model_cache_cleanup(document, comm):
    html = HTML()
    l = Card(header=html)

    model = l.get_root(document, comm)
    ref = model.ref['id']

    assert ref in l._models
    assert l._models[ref] == (model, None)
    assert ref in html._models

    l._cleanup(model)
    assert l._models == {}
    assert html._models == {}
Exemple #13
0
def test_console_output_disable_error(document, comm, get_display_handle):
    pane = HTML()
    with set_env_var('PANEL_CONSOLE_OUTPUT', 'disable'):
        model = pane.get_root(document, comm)
        handle = get_display_handle(model)

        try:
            1 / 0
        except Exception as e:
            pane._on_error(model.ref['id'], e)
        assert handle == {}

        pane._cleanup(model)
        assert model.ref['id'] not in state._handles
Exemple #14
0
def test_html_pane_width_height_stretch(document, comm):
    pane = HTML("<h1>Test</h1>", sizing_mode='stretch_width')

    # Create pane
    model = pane.get_root(document, comm=comm)
    assert model.style == {'width': '100%'}

    pane.sizing_mode = 'stretch_both'
    assert model.style == {'width': '100%', 'height': '100%'}

    pane.sizing_mode = 'stretch_height'
    assert model.style == {'height': '100%'}

    pane._cleanup(model)
Exemple #15
0
def test_console_output_accumulate_error(document, comm, get_display_handle):
    pane = HTML()
    model = pane.get_root(document, comm)
    handle = get_display_handle(model)

    try:
        1 / 0
    except Exception as e:
        pane._on_error(model.ref['id'], e)
    assert 'text/html' in handle
    assert 'ZeroDivisionError' in handle['text/html']

    try:
        1 + '2'
    except Exception as e:
        pane._on_error(model.ref['id'], e)
    assert 'text/html' in handle
    assert 'ZeroDivisionError' in handle['text/html']
    assert 'TypeError' in handle['text/html']

    pane._cleanup(model)
    assert model.ref['id'] not in state._handles
Exemple #16
0
def test_console_output_replace_error(document, comm, get_display_handle):
    pane = HTML()
    with set_env_var('PANEL_CONSOLE_OUTPUT', 'replace'):
        model = pane.get_root(document, comm)
        handle = get_display_handle(model)

        try:
            1 / 0
        except Exception as e:
            pane._on_error(model.ref['id'], e)
        assert 'text/html' in handle
        assert 'ZeroDivisionError' in handle['text/html']

        try:
            1 + '2'
        except Exception as e:
            pane._on_error(model.ref['id'], e)
        assert 'text/html' in handle
        assert 'ZeroDivisionError' not in handle['text/html']
        assert 'TypeError' in handle['text/html']

        pane._cleanup(model)
        assert model.ref['id'] not in state._handles
Exemple #17
0
def test_html_pane(document, comm):
    pane = HTML("<h1>Test</h1>")

    # Create pane
    model = pane.get_root(document, comm=comm)
    assert pane._models[model.ref['id']][0] is model
    assert model.text == "&lt;h1&gt;Test&lt;/h1&gt;"

    # Replace Pane.object
    pane.object = "<h2>Test</h2>"
    assert pane._models[model.ref['id']][0] is model
    assert model.text == "&lt;h2&gt;Test&lt;/h2&gt;"

    # Cleanup
    pane._cleanup(model)
    assert pane._models == {}
Exemple #18
0
"""Minimal Panel Hello World Example"""
from panel.pane import HTML

HTML("<h1>Hello Panel World from .py Code File</h1>").servable()
Exemple #19
0
def get_fast_js_panel():
    return HTML(FAST_JS_SCRIPT,
                width=0,
                height=0,
                sizing_mode="fixed",
                margin=0)
def _navigation_menu():
    return HTML(NAVIGATION_HTML)