So you've built a beautiful dashboard but your user decides to use a filter combination that returns no rows. Sometimes it's not even your users, it may just be that you have a structure where not all charts should have data returned. To account for the case when No Rows Returned, we can lean on Python to do our "error" handling for us. To check for the No Rows Returned condition, all you have to do is add look for the df to have nothing
df.size == 0
You can then add meaningful values, such as a blank string to be passed. That's what we did for this object where we built a dashboard with a chart for each major possible line item and account for it not being a part of the data returned.
# extract important variables def extract(df): if df.size == 0: return ['N/A', '', ''] else: current = str(prettify_num(df.iloc[0,1])) contract = str(prettify_num(df.iloc[0,0])) return [percent_difference(df), current, contract]
Please sign in to leave a comment.