A General Question About ColumnDataSource

Just a general question regarding Pandas DataFrame vs ColumnDataSource in the context of bokeh.

Are there any pros/cons for using a DataFrame directly in a call vs using a ColumnDataSource?

For example, I have a variable df which stores a DataFrame:

p = figure(source = df)

source = ColumnDataSource(df)
p = figure(source=source)

Do I gain anything by doing the second call? I’ve seen many examples of both, so I wanted to create a standard for my project

There is always a ColumnDataSource. If you pass a pandas data frame then Bokeh just creates one for you behind the scenes as a convenience. Creating a CDS yourself is useful if you want to share one data source between different plots or glyphs, refer to the data source in JS callbacks or other contexts, or have more control over which columns are in the data source.

1 Like