def construct(): from bowtie import App app = App(debug=True) app.add_sidebar(sigma) app.add(mainplot) app.schedule(0.1, walk) app.build()
def main(): from bowtie import App app = App(debug=True) app.add_sidebar(sigma) app.add(mainplot) app.schedule(0.1, walk) app.respond(pager, upgraph) return app
def test_used(buttons): """Test cell usage checks.""" app = App(rows=2, columns=2) for i in range(3): app.add(buttons[i]) app[0, 0] = buttons[3] app[0:1, 1] = buttons[3] app[1, 0:1] = buttons[3] app[1, 1] = buttons[3]
def test_build(build_path): """Tests the build process.""" reset_uuid() ctrl = Nouislider() viz = Plotly() app = App(directory=build_path) app.add_sidebar(ctrl) app.add(viz) app.subscribe(callback, ctrl.on_change) app.build()
def markdown(build_reset, monkeypatch): """Create markdown and text widgets.""" app = App(__name__, sidebar=True) app.add(mark) app.add_sidebar(side) app.add_sidebar(text) app.subscribe(text.on_change)(write) # pylint: disable=protected-access app._build() with server_check(app) as server: yield server
def test_build(build_reset, monkeypatch): """Tests the build process.""" reset_uuid() ctrl = Nouislider() viz = Plotly() app = App(__name__, sidebar=True) app.add_sidebar(ctrl) app.add(viz) app.subscribe(ctrl.on_change)(callback) # pylint: disable=protected-access app._build()
def test_build(build_path, monkeypatch): """Tests the build process.""" monkeypatch.setattr(App, '_sourcefile', lambda self: 'bowtie.tests.test_compile') reset_uuid() ctrl = Nouislider() viz = Plotly() app = App() app.add_sidebar(ctrl) app.add(viz) app.subscribe(callback, ctrl.on_change) # pylint: disable=protected-access app._build()
def components(build_path, monkeypatch): """App with all components.""" monkeypatch.setattr(App, '_sourcefile', lambda self: 'bowtie.tests.test_components') controllers, visuals = create_components() app = App(rows=len(visuals)) for controller in controllers: # pylint: disable=protected-access assert COMPONENT_REGISTRY[controller._uuid] == controller app.add_sidebar(controller) for vis in visuals: # pylint: disable=protected-access assert COMPONENT_REGISTRY[vis._uuid] == vis app.add(vis) # pylint: disable=protected-access app._build() env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(), os.environ.get('PYTHONPATH', '')) server = subprocess.Popen(os.path.join(build_path, 'src/server.py'), env=env) time.sleep(5) yield server.kill()
def test_components(chrome_driver, build_path): """Tests plotly.""" app = App(rows=len(visuals), directory=build_path) for controller in controllers: app.add_sidebar(controller) for vis in visuals: app.add(vis) app.build() env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(), os.environ.get('PYTHONPATH', '')) server = subprocess.Popen(os.path.join(build_path, 'src/server.py'), env=env) time.sleep(5) chrome_driver.get('http://localhost:9991') chrome_driver.implicitly_wait(5) logs = chrome_driver.get_log('browser') for log in logs: if log['level'] == 'SEVERE': raise Exception(log['message']) server.kill()
def markdown(build_reset, monkeypatch): """Create markdown and text widgets.""" app = App(__name__, sidebar=True) app.add(mark) app.add_sidebar(side) app.add_sidebar(text) app.subscribe(text.on_change)(write) # pylint: disable=protected-access app._build() with server_check(app) as server: yield server
def dummy(build_reset, monkeypatch): """Create basic app.""" app = App(__name__) app.add(button) app.subscribe(button.on_click)(click) app._build() # pylint: disable=protected-access with server_check(app) as server: yield server
def test_used(buttons): """Test cell usage checks.""" app = App(rows=2, columns=2) for i in range(3): app.add(buttons[i]) with pytest.raises(UsedCellsError): app[0, 0] = buttons[3] with pytest.raises(UsedCellsError): app[0:1, 1] = buttons[3] with pytest.raises(UsedCellsError): app[1, 0:1] = buttons[3] app[1, 1] = buttons[3]
def test_append_to_partial(buttons): """Append button to partial cell.""" app = App(columns=2) app[0] = buttons[0] with pytest.raises(KeyError): app[0, 0] += buttons[1] with pytest.raises(SpanOverlapError): app[0, 0] = buttons[1]
def dummy(build_path, monkeypatch): """Create basic app.""" monkeypatch.setattr(App, '_sourcefile', lambda self: 'bowtie.tests.test_cache') app = App() app.add(button) app.subscribe(click, button.on_click) # pylint: disable=protected-access app._build() with server_check(build_path) as server: yield server
def dummy(build_reset, monkeypatch): """Create basic app.""" app = App(__name__) app.add(button) app.subscribe(button.on_click)(click) app._build() # pylint: disable=protected-access with server_check(app) as server: yield server
def test_markdown(chrome_driver, build_path): """Test markdown and text widgets.""" app = App(directory=build_path) app.add(mark) app.add_sidebar(side) app.add_sidebar(text) app.subscribe(write, text.on_change) app.build() env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(), os.environ.get('PYTHONPATH', '')) server = subprocess.Popen(os.path.join(build_path, 'src/server.py'), env=env) time.sleep(5) chrome_driver.get('http://*****:*****@style='grid-area: 1 / 2 / 2 / 3; position: relative;']") assert 'top' in output.text assert 'middle' in output.text assert 'link' in output.text txtctrl.send_keys('apple') time.sleep(1) assert 'apple' in output.text txtctrl.send_keys('banana') time.sleep(1) assert 'apple' in output.text assert 'banana' in output.text server.kill()
def markdown(build_path, monkeypatch): """Create markdown and text widgets.""" monkeypatch.setattr(App, '_sourcefile', lambda self: 'bowtie.tests.test_editor') app = App() app.add(mark) app.add_sidebar(side) app.add_sidebar(text) app.subscribe(write, text.on_change) # pylint: disable=protected-access app._build() env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(), os.environ.get('PYTHONPATH', '')) server = subprocess.Popen(os.path.join(build_path, 'src/server.py'), env=env) time.sleep(5) yield server.kill()
def test_grid_index(buttons): """Test grid indexing checks.""" app = App(rows=2, columns=2) with pytest.raises(GridIndexError): app[-5] = buttons[0] app[-1] = buttons[0] with pytest.raises(GridIndexError): app[2] = buttons[0] app[1] = buttons[0]
def test_getitem(buttons): """Test grid indexing checks.""" but = buttons[0] app = App(rows=2, columns=2) with pytest.raises(GridIndexError): app[3] = but with pytest.raises(GridIndexError): app[1, 2, 3] = but with pytest.raises(GridIndexError): # pylint: disable=invalid-slice-index app['a':3] = but with pytest.raises(GridIndexError): app['a'] = but with pytest.raises(GridIndexError): app[3, 'a'] = but with pytest.raises(GridIndexError): app['a', 3] = but with pytest.raises(GridIndexError): app[0, 0::2] = but with pytest.raises(GridIndexError): app[0, 1:-1:-1] = but app[1, ] = but assert sum(app._root._used.values()) == 2 app[0, :] = but assert sum(app._root._used.values()) == 4 app = App(rows=2, columns=2) app[0:1, 1:2] = but assert sum(app._root._used.values()) == 1 app[1:, 0:] = but assert sum(app._root._used.values()) == 3 app = App(rows=2, columns=2) app[-1, :2] = but assert sum(app._root._used.values()) == 2 app = App(rows=1, columns=2) app[0, :2] = but assert sum(app._root._used.values()) == 2 app = App(rows=1, columns=2) app[0] = but assert sum(app._root._used.values()) == 2 app = App(rows=2, columns=2) app[:2] = but assert sum(app._root._used.values()) == 4
def main(): app = App(rows=3, columns=2, sidebar=False, debug=True) app.rows[0].auto() app[0] = catdd app[1] = stars app[2, 0] = busy app[2, 1] = revdate app.subscribe(viz, catdd.on_change) app.subscribe(vizplace, stars.on_click) return app
def test_all_used(buttons): """Test all cells are used.""" app = App(rows=2, columns=2) for i in range(4): app.add(buttons[i]) check_all_cells_used(app._root) app = App(rows=2, columns=2) app[0, 0] = buttons[0] app[0, 1] = buttons[1] app[1, 0] = buttons[2] app[1, 1] = buttons[3] check_all_cells_used(app._root) app.add(buttons[2]) assert len(app[1, 1]) == 2 app = App(rows=2, columns=2) app[0] = buttons[0] app[1, 0] = buttons[2] app[1, 1] = buttons[3] check_all_cells_used(app._root) app.add(buttons[2]) assert len(app[1, 1]) == 2
def test_plotly(chrome_driver, build_path): """Tests plotly.""" app = App(directory=build_path) app.add(viz) app.add_sidebar(ctrl) app.add_sidebar(ctrl2) app.subscribe(callback, ctrl.on_change) app.subscribe(callback, ctrl2.on_click) app.build() env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(), os.environ.get('PYTHONPATH', '')) server = subprocess.Popen(os.path.join(build_path, 'src/server.py'), env=env) time.sleep(5) chrome_driver.get('http://localhost:9991') chrome_driver.implicitly_wait(5) assert chrome_driver.title == 'Bowtie App' button = chrome_driver.find_element_by_class_name('ant-btn') button.click() points = chrome_driver.find_elements_by_class_name('point') logs = chrome_driver.get_log('browser') for log in logs: if log['level'] == 'SEVERE': raise Exception(log['message']) assert len(points) == 4 server.kill()
def app(): """Simple app.""" return App(rows=2, columns=2)
from bowtie.control import Dropdown, Slider from bowtie.visual import Plotly, Table from bowtie.html import Markdown, Header import numpy as np import pandas as pd import plotlywrapper as pw from sklearn.kernel_ridge import KernelRidge iris = pd.read_csv('./iris.csv') iris = iris.drop(iris.columns[0], axis=1) attrs = iris.columns[:-1] app = App(rows=2, columns=3, sidebar=True, background_color='PaleTurquoise', debug=True) description = Markdown("""Bowtie Demo =========== Demonstrates interactive elements with the iris dataset. Select some attributes to plot and select some data on the 2d plot. Change the alpha parameter to see how that affects the model. """) xdown = Dropdown(labels=attrs, values=attrs) ydown = Dropdown(labels=attrs, values=attrs) zdown = Dropdown(labels=attrs, values=attrs) alphaslider = Slider(start=10, minimum=1, maximum=50) mainplot = Plotly()
def test_all_used(buttons): """Test all cells are used.""" app = App(rows=2, columns=2) for i in range(4): app.add(buttons[i]) assert list(app._root._used.values()) == 4 * [True] app = App(rows=2, columns=2) app[0, 0] = buttons[0] app[0, 1] = buttons[1] app[1, 0] = buttons[2] app[1, 1] = buttons[3] assert list(app._root._used.values()) == 4 * [True] with pytest.raises(NoUnusedCellsError): app.add(buttons[2]) app = App(rows=2, columns=2) app[0] = buttons[0] app[1, 0] = buttons[2] app[1, 1] = buttons[3] assert list(app._root._used.values()) == 4 * [True] with pytest.raises(NoUnusedCellsError): app.add(buttons[2])
def multiple_views(build_reset, monkeypatch): """Create multiple views app.""" app = App(__name__, sidebar=True) view1 = View() # pylint: disable=unused-variable assert view1._uuid == 2 # pylint: disable=protected-access view2 = View() view2.add(table) app.add_route(view2, 'view2') app.add(table) app.add_sidebar(ctrl) app.add_sidebar(ctrl2) app.subscribe(ctrl.on_change)(app.subscribe(ctrl2.on_click)(callback)) app._build() # pylint: disable=protected-access with server_check(app) as server: yield server
def test_subscribe_error(): """Subscribe with incorrect argument order.""" app = App() button = Button() with pytest.raises(TypeError): app.subscribe(3, button.on_click)
def plotly(build_reset, monkeypatch): """Create plotly app.""" app = App(__name__, sidebar=True) app.add(viz) app.add_sidebar(ctrl) app.add_sidebar(ctrl_range) app.add_sidebar(ctrl2) app.subscribe(ctrl.on_change)(app.subscribe(ctrl2.on_click)(callback)) # pylint: disable=protected-access app._build() with server_check(app) as server: yield server
def components(build_reset, monkeypatch): """App with all components.""" controllers, visuals, htmls = create_components() app = App(__name__, rows=len(visuals), sidebar=True) for controller in controllers: # pylint: disable=protected-access assert COMPONENT_REGISTRY[controller._uuid] == controller app.add_sidebar(controller) for vis in visuals: # pylint: disable=protected-access assert COMPONENT_REGISTRY[vis._uuid] == vis app.add(vis) for htm in htmls: # pylint: disable=protected-access assert COMPONENT_REGISTRY[htm._uuid] == htm app.add_sidebar(htm) assert len( COMPONENT_REGISTRY) == len(controllers) + 2 * len(visuals) + len(htmls) # pylint: disable=protected-access app._build() # run second time to make sure nothing weird happens with subsequent builds app._build() with server_check(app) as server: yield server
def multiple_views(build_reset, monkeypatch): """Create multiple views app.""" app = App(__name__, sidebar=True) view1 = View() # pylint: disable=unused-variable assert view1._uuid == 2 # pylint: disable=protected-access view2 = View() view2.add(table) app.add_route(view2, 'view2') app.add(table) app.add_sidebar(ctrl) app.add_sidebar(ctrl2) app.subscribe(ctrl.on_change)(app.subscribe(ctrl2.on_click)(callback)) app._build() # pylint: disable=protected-access with server_check(app) as server: yield server
def test_subscribe_error(): """Subscribe with incorrect argument order.""" app = App() with pytest.raises(IndexError): app.subscribe()
def main(): from bowtie import App app = App(title='Network DownScaler') app.add(sine_plot) app.add_sidebar(upload) app.subscribe(upload_listener, upload.on_upload) app.add_sidebar(scale_factor_input) app.subscribe(update_scale_factor, scale_factor_input.on_change) app.add_sidebar(freq_slider) app.subscribe(slider_listener, freq_slider.on_change) app.add_sidebar(dropdown_src) app.add_sidebar(dropdown_dst) app.subscribe(dropdown_src_listener, dropdown_src.on_change) app.subscribe(dropdown_dst_listener, dropdown_dst.on_change) return app
def multiple_views(build_path, monkeypatch): """Create multiple views app.""" monkeypatch.setattr(App, '_sourcefile', lambda self: 'bowtie.tests.test_multiple') app = App() view1 = View() # pylint: disable=unused-variable assert view1._uuid == 2 # pylint: disable=protected-access view2 = View() view2.add(table) app.add_route(view2, 'view2') app.add(table) app.add_sidebar(ctrl) app.add_sidebar(ctrl2) app.subscribe(callback, ctrl.on_change) app.subscribe(callback, ctrl2.on_click) app._build() # pylint: disable=protected-access env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(), os.environ.get('PYTHONPATH', '')) server = subprocess.Popen(os.path.join(build_path, 'src/server.py'), env=env) time.sleep(5) yield server.kill()
def plotly(build_path, monkeypatch): """Create plotly app.""" monkeypatch.setattr(App, '_sourcefile', lambda self: 'bowtie.tests.test_plotly') app = App() app.add(viz) app.add_sidebar(ctrl) app.add_sidebar(ctrl2) app.subscribe(callback, ctrl.on_change) app.subscribe(callback, ctrl2.on_click) # pylint: disable=protected-access app._build() env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(), os.environ.get('PYTHONPATH', '')) server = subprocess.Popen(os.path.join(build_path, 'src/server.py'), env=env) time.sleep(5) yield server.kill()
#!/usr/bin/env python """Example Bowtie App.""" from bowtie import App from bowtie.control import Nouislider from bowtie.visual import Plotly from bowtie import Pager, cache, command import numpy as np from numpy import random as rng import plotlywrapper as pw app = App(debug=True, sidebar=True) pager = Pager() sigma = Nouislider(start=0., minimum=0.1, maximum=50.) mainplot = Plotly() app.add_sidebar(sigma) app.add(mainplot) def initialize(): cache.save('data', [0.] * 100) @app.subscribe(pager) def upgraph(): data = cache.load('data') value = float(sigma.get()) data.pop(0)
#!/usr/bin/env python """Example Bowtie App.""" from bowtie import App from bowtie.control import Nouislider from bowtie.visual import Plotly from bowtie import Pager, cache, command import numpy as np from numpy import random as rng import plotlywrapper as pw app = App(debug=True, sidebar=True) pager = Pager() sigma = Nouislider(start=0., minimum=0.1, maximum=50.) mainplot = Plotly() app.add_sidebar(sigma) app.add(mainplot) def initialize(): cache.save('data', [0.] * 100) @app.subscribe(pager) def upgraph(): data = cache.load('data') value = float(sigma.get()) data.pop(0) data.append(value * rng.randn() + data[-1])
def components(build_reset, monkeypatch): """App with all components.""" controllers, visuals, htmls = create_components() app = App(__name__, rows=len(visuals), sidebar=True) for controller in controllers: # pylint: disable=protected-access assert COMPONENT_REGISTRY[controller._uuid] == controller app.add_sidebar(controller) for vis in visuals: # pylint: disable=protected-access assert COMPONENT_REGISTRY[vis._uuid] == vis app.add(vis) for htm in htmls: # pylint: disable=protected-access assert COMPONENT_REGISTRY[htm._uuid] == htm app.add_sidebar(htm) assert len(COMPONENT_REGISTRY) == len(controllers) + 2 * len(visuals) + len(htmls) # pylint: disable=protected-access app._build() # run second time to make sure nothing weird happens with subsequent builds app._build() with server_check(app) as server: yield server