Skip to content

Instantly share code, notes, and snippets.

@mebaysan
Last active September 21, 2020 19:19
Show Gist options
  • Save mebaysan/8d58ea2fe490d1155131e2307220116c to your computer and use it in GitHub Desktop.
Save mebaysan/8d58ea2fe490d1155131e2307220116c to your computer and use it in GitHub Desktop.
Intro Plotly Dash Callback
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
my_input = dcc.Input(id='my-input', # component id'si
type='text', # input tipi
placeholder='Aramak İstediğiniz Metni Girin...', # input box boş ise ne yazacak
debounce=True, # enter'a basmadan kutuya her girileni post etmesin
value='' # başlangıç değeri
)
LAYOUT = html.Div(children=[
html.H1('Dropdown Çalışması', style={
'textAlign': 'center',
'color': 'red',
}),
my_input,
html.H4(id='my-output') # hedef component'imiz
])
app.layout = LAYOUT
@app.callback(
dash.dependencies.Output(component_id="my-output", component_property="children"),
dash.dependencies.Input("my-input", "value"),
)
def set_value(value): # Input alacağımız componenti set ettikten sonra callback çağrıldığında bu fonksiyona parametre olarak component_property gelecek
if value:
return f'Aradığınız kelime -> {value}' # Hedef component'imizin children özelliğine stringi return ediyoruz
if __name__ == '__main__':
app.run_server()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment