voila-dashboards / voila-vuetify

Dashboard template for Voilà based on VuetifyJS
Other
154 stars 41 forks source link

How do I make a button trigger draw function and show result in vuetify ? #35

Closed eromoe closed 4 years ago

eromoe commented 4 years ago

Hello,

It is struggling for me to figure it out . Now I have wrote a basic ugly working code by ipywidgets . It is like


def get_feature(input_value1, input_value2, ):
      # ...
      return df

def get_model(input_value3, input_value4, ):
      # ...
      return pickled_model

def click_handler():

    # do validation to  input_value1, input_value2, input_value3, input_value4
    # I don't know how to alert error here

    feature = get_feature(..)
    mode = get_model(..)

    with top_out:
        clear_output(wait=True)
        draw(feature, model)

def draw(feature, model):
    f = plt.figure()

    # matplotlib plot
    plt.plot(...)

    # seaborn plot
    sns.boxplot(...)

    # plotly.py plot
    fig = go.Figure()
    fig.add_trace(
        go.Line(
            x=df1.ds,
            y=df1.y,
        )
    )
    py.iplot(fig)

button = widgets.Button(description='view')      
button.on_click(click_handler)

top_out = widgets.Output()

container = widgets.VBox(
    children=(
        widgets.HBox([target_date_input, *input_lst, button]),
        top_out,
    )
)

display(container)

I didn't found a example for my case. Could you give me a guide ?

mariobuikhuizen commented 4 years ago

For the button click part: (see: https://ipyvuetify.readthedocs.io/en/latest/usage.html#events)

def click_handler(*args):
    ...

button = v.Btn(children=['view'])
button.on_event('click', click_handler)

For the result you will need to keep using the Output widget unless you use a plot library that has support for widgets like bqplot or ploty's FigureWidget.

eromoe commented 4 years ago

Thank you. Now I understand the figure object must support some interact function, only in that way I can put different figure object to v.Container . If insist using matplotlib and seaborn , must need output widget, right ?