StormsEdge
StormsEdge

Reputation: 885

Error Creating Select List in Bokeh

I am trying to create a Select widget driven bar graph and am struggling on the very first piece of purely implementing the Select widget.

I currently have a list of companies that I generate with the following:

tech_firms = list(sorted(tech_valid['Company Name'].unique()))

Which as far as I know is simply a list. When I debug in Jupyter I get what looks like a list output (with a scroll bar)

Not Working: The below does not work and I receive the error: expected an element of either List(Either(String, Tuple(Either(Int, String),String))) or Dict(String, List(Either(String, Tuple(Either(Int,String)(,String)))), got Select(description='Tech Firms', options= ....) and the list of all the names within tech_firms

#drop down population
select = Select(title="Tech Firms", value="Apple", options=tech_firms)
show(widgetbox(select))

If I try the following it works, but it's not at all an effective solution given that I have many names in the list and as the dataset changes and evolves it's quite plausible new companies could appear and others could disappear. What am I missing?

Working:

#drop down population
select = Select(title='Tech Firms', value='Apple', options=['Apple', 'Google', 'DeepMind', 'Amazon'])
show(widgetbox(select))

Showing some values that are in tech_firms as requested: (I pulled this from the exception so that it shows as is during the throw):

got Select(description='Tech Firms', options=('Apple', 'Amazon', 'DeepMind', 'Google', 'Tesla, Inc.', 'Arlington Corp.', 'YouTube')

Upvotes: 1

Views: 378

Answers (2)

Snehal Nair
Snehal Nair

Reputation: 191

It doesn't work when you have na in your unique list. So drop na before you call unique().

tech_valid.dropna()
tech_valid['Company Name'].unique().tolist()

Upvotes: 0

StormsEdge
StormsEdge

Reputation: 885

The solution I found was in that I was unnecessarily designating the dataframe column as a list. Apparently, for some reason, this does not work.

My solution was to create a new var without the list cast by the following tech_firms_list = tech_firms['Company Name'].unique()

Upon creation of the select drop down I sorted the list when processing the options param via the following:

select = Select(title="Tech Firms", value="Amazon Inc.", options=sorted(tech_firms_list))

Apparently the list cast caused some issues as an argument. If anyone knows exactly why that would happen please let me know I would like to have a firm understanding of these mechanics.

Upvotes: 1

Related Questions