@vspadotto wrote:
Can someone help me understand how to do conditional formatting with a function?
This is my function, and it will return the variance for a stock.
def current_change(stock_id='FB'): price_url = f'https://financialmodelingprep.com/api/v3/quote/{stock_id}' current_price = get_jsonparsed_data(price_url) change = "{0:.2f}".format(current_price[0]['changesPercentage']) return changeSo I have a Led Display with the number (it’s actually a str) the function will return and would like to make it red if it’s negative and green if it’s positive.
color = '#fc7d7b' if '-' in current_change() else '#88fc4a' daq.LEDDisplay( id='current_variance', label = 'Variance (%)', value= current_change(), backgroundColor='#272727', color=color ) @app.callback( Output(component_id='current_variance', component_property='color'), [Input(component_id='dropdown select', component_property='value')] ) def update_color(current_change): color = '#fc7d7b' if '-' in current_change() else '#88fc4a' return colorThis is the error that I get TypeError: ‘str’ object is not callable - and it’s related to the callback.
Posts: 3
Participants: 2