def version_three(): app = Zig() section = Div(section=[ H6("Title!"), Div(section=[ Input_text("intial_value", id="my-put"), Div("test") ]), LINE_BREAK, Div(id="my-output") ]) app.add(section) def update_ouput_div(input_value): return "Output: {}".format(input_value) # Input uses id by default. use key arg for other attributes add_interaction(Interact(Input(inp.id, "value"), Output(ouput.id, "content"), update_ouput_div) )
def basic_interaction(self): app = Zig("test_app") return_callback = lambda x: x zig_interaction = Interact(InteractIn(Input(id="234"), "value"), InteractOut(Div(id="345"), "content"), return_callback) app.add_interaction(zig_interaction) return app
def test_one(): app = Zig() def return_fn(in_value): return in_value zig_interaction = Interact(InteractIn(Input(id="123"), "value"), InteractOut(Div(id="456"), "content"), return_fn) app.add_interaction(zig_interaction) # NOTE: able to run app with interaction alone? # what if user forgotten to add element in? return app
def test_passed_Flask_argument(self, mocker, test_app): mocker.patch.object(Zig, '_initiate_container') container_name = "Flask" app_name = "test_app" test_app = Zig("test_app", container=container_name) test_app._initiate_container.assert_called_once_with( container_name, app_name)
def test_interaction_render_browser(self, basic_interaction, chrome_browser): # use python requests to send get and parse api app = basic_interaction app = Zig("test app") app.add(Div(id=123)) try: chrome_browser.start_server_thread(app) except Exception: raise Exception("Unable to start server") if chrome_browser.thread_started: chrome_browser.get("http://127.0.0.1:5000/") # thread starts """
def version_two(): app = Zig() section = Div() header = H6("Title!") output = Div(id="my-output") # method 1 # possible to add siblings too? section2 = Div(section=[ Input_text("intial_value", id="my-put"), Div("test") ]) # mtd 2 section2 = Div().add([Input_text("intial_value", id="my-put"), Div("test")]) # wrap everything in div section.add([header, section2, LINE_BREAK, ouput]) app.add(section)
def version_one(): app = Zig() section = Div() header = H6("Title!") output = Div(id="my-output") section2 = Div("Input :" ) inp = Input_text("initial_value", id="my-input") section2.add(inp) # wrap everything in div section.add([header, section2, LINE_BREAK, ouput]) app.add(section) def update_ouput_div(input_value): return "Output: {}".format(input_value) interaction = Interact(Input(inp.id, "value"), Output(ouput.id, "content"), update_ouput_div) app.add_interaction(interaction)
def test_one(): """ Test with 2 basic inputs """ app = Zig() def return_fn(in_value, in_value2): return in_value + in_value2 textbox = InputText("initial value", id="123") textbox2 = InputText("this too", id="985") display = Div(id="456") frame = Div().add([textbox, textbox2, display]) app.add(frame) zig_interaction = Interact( [InteractIn(textbox), InteractIn(textbox2)], InteractOut(display), return_fn) app.add_interaction(zig_interaction) # NOTE: able to run app with interaction alone? # what if user forgotten to add element in? return app
def test_one(): app = Zig() def return_fn(in_value): return in_value textbox = InputText("initial value", id="123") display = Div(id="456") frame = Div().add([textbox, display]) app.add(frame) zig_interaction = Interact(InteractIn(textbox), InteractOut(display), return_fn) app.add_interaction(zig_interaction) # NOTE: able to run app with interaction alone? # what if user forgotten to add element in? return app
def test(): app = Zig() df = pd.read_csv( 'https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv' ) # how does Graph get the initial data from update_graph? graph = Graph(id="graph-with-slider") slider = Slider( df['year'].min, id="year-slider", min=df['year'].min(), max=df['year'].max(), marks={str(year): str(year) for year in df['year'].unique()}, step=None) def update_graph(selected_year): filtered_df = df[df.year == selected_year] fig = px.scatter(filtered_df, x="gdpPercap", y="lifeExp", size="pop", color="continent", hover_name="country", log_x=True, size_max=55) # important: how to send transition setting to angular? fig.update_layout(transition_duration=500) return fig app.add(Div(section=[graph, slider])) app.add_interaction( Interact(Input(slider.id, "value"), Output(graph.id, 'figure'), update_graph))
def test_app_name_set_automatically(self, app_name): test_app = Zig(app_name) assert test_app.app_name == app_name
def test_zig_section(self): app = Zig() test_section = [] assert app.section == test_section assert isinstance(app.section_control, CoreSection)
from setup import setup # add zig as package setup() from zig import Zig from zig.main_components import Graph from zig.html_components import Div import pandas as pd import plotly.express as px # all default app = Zig() df = pd.DataFrame({ "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"], "Amount": [4, 1, 2, 2, 4, 5], "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"] }) fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group") app.add(Graph(fig)) app.add(Graph(fig)) app.add(Div()) if __name__ == "__main__": app.run()
from zig import Zig # all default ''' host: 127.0.0.1 port: 5000 asset url: /assets asset folder: assets template folder: templates index file: index_flask ''' app = Zig() if __name__ == "__main__": app.run()
def test_app(self, mocker): mocker.patch('zig.FlaskContainer', spec=True) return Zig()
def test_passed_container(self, mocker, test_app): mock_container = mocker.Mock(spec=FlaskContainer) test_app = Zig(container=mock_container) assert isinstance(test_app.container, Container)
from setup import setup # add zig as package setup() from zig import Zig from zig.main_components import Graph from zig.html_components import Div import pandas as pd import plotly.express as px # all default app = Zig() div = Div() div_child = Div() div_child.add([Div(), Div(), Graph()]) div.add([div_child, Div()]) app.add(div) if __name__ == "__main__": expected = { 'sections': { 0: { 'dom_type': 'div', 'data': { 'id': None, 'content': '' },
from setup import setup # add zig as package setup() from zig import Zig from zig.main_components import Graph from zig.html_components import Div import pandas as pd import plotly.express as px # all default app = Zig() app.add(Div()) app.add(Div(id="123")) app.add(Div()) app.add(Div()) if __name__ == "__main__": result = app.run() print(result)