Hover tool not working in Bokeh
<p>I have a table that contains the number of times a student accessed an activity.</p>

<pre><code>  df_act5236920.head()

    activities  studs
 0  3.0       student 1
 1  4.0       student 10
 2  5.0       student 11
 3  6.0       student 12
 4  2.0       student 13
 5  4.0       student 14
 6  19.0      student 15
</code></pre>

<p>If I try to add the hover tool to the bar chart created by this dataframe through the code below:</p>

<pre><code> from bokeh.charts import Bar
 from bokeh.models import Legend

 from collections import OrderedDict
 TOOLS = "pan,wheel_zoom,box_zoom,reset,hover,save"
 bar = Bar(df_act5236920,values='activities',label='studs',title = "Activity 5236920 performed by students",
      xlabel="Students",ylabel="Activity",legend=False,tools=TOOLS)
 hover = bar.select_one(HoverTool)
 hover.point_policy = "follow_mouse"
 hover.tooltips = OrderedDict([
     ("Student Name", "@studs"),
     ("Access Count", "@activities"),
 ])
 show(bar)
</code></pre>

<p>When I hover over the bar chart, it shows the student value but not the activities values, I even tried using "$activities" but the result is still the same.</p>

<p><a href="http://i.stack.imgur.com/kne1z.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/kne1z.jpg" alt="enter image description here"></a></p>

<p>I tried using ColumnDataSource instead of DataFrame based on other stack overflow questions I read, as is apparent in the code below:</p>

<pre><code>source = ColumnDataSource(ColumnDataSource.from_df(df_act5236920))

from collections import OrderedDict
TOOLS = "pan,wheel_zoom,box_zoom,reset,hover,save"
bar = Bar('studs','activities',source=source, title = "Activity 5236920 performed by students",tools=TOOLS)
hover = bar.select_one(HoverTool)
hover.point_policy = "follow_mouse"
hover.tooltips = OrderedDict([
    ("Student Name", "@studs"),
    ("Access Count", "@activities"),
])
show(bar)
</code></pre>

<p>It gives me the following error:</p>

<pre><code>    ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-76-81505464c390&gt; in &lt;module&gt;()
  3 # bar = Bar(df_act5236920,values='activities',label='studs',title = "Activity 5236920 performed by students",
  4 # xlabel="Students",ylabel="Activity",legend=False,tools=TOOLS)
  ----&gt; 5 bar = Bar('studs','activities',source=source, title = "Activity 5236920 performed by students",tools=TOOLS)
  6 hover = bar.select_one(HoverTool)
  7 hover.point_policy = "follow_mouse"

C:\Anaconda2\lib\site-packages\bokeh\charts\builders\bar_builder.pyc in  Bar(data, label, values, color, stack, group, agg, xscale, yscale, xgrid, ygrid, continuous_range, **kw)
319     kw['y_range'] = y_range
320 
--&gt; 321     chart = create_and_build(BarBuilder, data, **kw)
322 
323     # hide x labels if there is a single value, implying stacking only

C:\Anaconda2\lib\site-packages\bokeh\charts\builder.pyc in create_and_build(builder_class, *data, **kws)
 66     # create the new builder
 67     builder_kws = {k: v for k, v in kws.items() if k in builder_props}
---&gt; 68     builder = builder_class(*data, **builder_kws)
 69 
 70     # create a chart to return, since there isn't one already

C:\Anaconda2\lib\site-packages\bokeh\charts\builder.pyc in __init__(self, *args, **kws)
292             # make sure that the builder dimensions have access to the chart data source
293             for dim in self.dimensions:
--&gt; 294                 getattr(getattr(self, dim), 'set_data')(data)
295 
296             # handle input attrs and ensure attrs have access to data

C:\Anaconda2\lib\site-packages\bokeh\charts\properties.pyc in set_data(self, data)
170             data (`ChartDataSource`): the data source associated with the chart
171         """
--&gt; 172         self.selection = data[self.name]
173         self._chart_source = data
174         self._data = data.df

TypeError: 'NoneType' object has no attribute '__getitem__'
</code></pre>

<p>I even tried creating the ColumnDataSource from scratch by passing the columns of the dataframe to it in the form of a list of values, but I still got the same error as the one shown above</p>

<pre><code>source = ColumnDataSource(data=dict(
     studs=students,
     activities=activity_5236920,
))
</code></pre>

<p>I'm having the same issue when I try to implement the hovertool on a heatmap as well. Can anyone help in how to fix this?</p>

<p>So, after going through a lot of the documentation, I've finally figured out a few things.</p>

<p>Firstly, the NoneType error was due to the fact that for a bar chart, you need to pass the dataframe as well as the ColumnDataSource, for the bar-chart to display. 
So the code needed to be:</p>

<pre><code>bar = Bar(df_act5236920,values='activities',label='studs',title = "Activity 5236920 performed by students",
      xlabel="Students",ylabel="Activity",legend=False,tools=TOOLS,source=source)
</code></pre>

<p>Notice how the dataframe name and source=source are both mentioned in the Bar() method.
For the second issue of the value not being displayed, I used @height which essentially displayed the height of the selected bar, which in this case was the count value.</p>

<pre><code>hover.tooltips = OrderedDict([
   ("Student Name", "@studs"),
   ("Access Count", "@height"),
]) 
</code></pre>

<p>For the student name value, @x and @studs both work. But the only thing I still couldn't resolve was that although I have mentioned the ColumnDataSource "source", it didn't really accomplish anything for me because when I try to use @activities in hover.tooltips, it still gives me a response of "???". So, I'm not sure what that is all about. And it is an issue that I'm sturggling with in another Time Series visualisation that I'm trying to build.</p>

python pandas hover tooltip bokeh