Data table Download option after setting filters

I need help with setting up the bokeh app to make an interactive data table and download the data table as a csv file based on slider inputs

I have about 60 such parameters and about 150 thousand combinations of them.
I am trying to fix up some 15 to 20 sliders and trying to play with them to see which of these combinations fall into my criteria based on some filters.I have used some filters to sort the data and have selected top 100 of them based on the filters the user would input,
currently, with this code, the table does shows up and sliders work well updating the data table
I need help saving this table when ever user wishes to based on the filter the user has set. some thing similar to saving a calculation result file
I have written the code on the latest Python 3.7 and latest Bokeh 1.2.0 and latest Pandas on Spyder IDE. I tried doing custom JS since I don’t really know to programme on JavaScript, I would rather avoid it completely.
import numpy as np

import pandas as pd
from pandas import DataFrame
import numpy as np
from bokeh.models import HoverTool
from bokeh.themes import built_in_themes
from bokeh.io import curdoc 
from bokeh.models import Slider,DataTable, TableColumn
from bokeh.plotting import figure, output_file, show, ColumnDataSource
from bokeh.layouts import row, column, gridplot
from bokeh.models.widgets import Tabs, Panel
from bokeh.core.properties import Float, Instance, Tuple, Bool, Enum
from bokeh.models import InputWidget
from bokeh.models.callbacks import Callback
from bokeh.models.widgets import RangeSlider
df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD')) 
source = ColumnDataSource(df)
a_Slider= RangeSlider(start=min(df['A']), end=max(df['A']), value=(min(df['A']),max(df['A'])), step=1, title='YY in mm')
B_Slider = RangeSlider(start=min(df['B']), end=max(df['B']), value=(min(df['B']),max(df['B'])), step=1, title='ZZ')
def callback(attr,new,old)
    A_s = A_Slider.value[0]
    A_e = A_Slider.value[1]
    B_1_s= B_1_Slider.value[0]
    B_1_e= B_1_Slider.value[1]
    dff= pd.DataFrame(df[(df.A >=A_s) & (df.A <= A_e) & (df.B_1 >= B_s) & (df.B <= B_e)])
    source.data = ColumnDataSource.from_df(dff)
    #function ends here   
A_Slider.on_change("value",callback)
B_Slider.on_change("value",callback)
columns = [TableColumn(field='No.', title='Concept No'),
           TableColumn(field='A', title='a'),
           TableColumn(field='B', title='z_1'),
           TableColumn(field='C', title='z_2'),
           TableColumn(field='D', title='u')]
table=DataTable(source=source,columns = columns)
Graphs = row([table])
Controls1= column([A_Slider,B_Slider])
layout= row(Controls1,Graphs)

I am expecting a some guidance on creating a button for download of the data table with user defined names in the user defined directories, so that if the user wishes the filtered data can be downloaded
on a second priority if you could guide me to write a loop for each of sliders definition and callback
I don’t want to repeat every line again and again.

Please shorten the code sample to the absolute bare minimum needed to ask the question. There are tens of lines of code that have nothing to do with this problem (unnecessary or repeated imports, adding a theme and title, etc) People will be more inclined to volunteer their time on your behalf if you do the up-front prep to make the question as simple and focused as possible.

@VITTAL_S_S I am sorry to keep nitpicking but please format the code as well, it is not currently usable as all the indentation has been lost. Discourse provides nice code formatting tools (you can type triple-backtick blocks or use the edit toolbar button)

I have made the necessary changes
Could you please guide me with the updated question (hoping that it is well put together)

There is nothing offhand strange about the code above, it looks like basically any other Bokeh app. To determine anything else I would have to run and debug/profile myself. I.e. I would need to be able to:

  • copy and paste the code in a text editor
  • immediately run it with no modifications whatsoever

Note this also means any data files would be necessary to run, or (more likely in this case) they would need to be replaced by equivalent simulated/fake data so that things execute and still demonstrate the problem.

Otherwise all I can do at this point is to re-iterate my suggestion to put in some print statements to report timings for various parts of the program to determine where the hotspots are.

Hey @Brayan, i have totally changed the question
now i am asking help to download the table and also to have a colour coding for the values
My code runs fine and i am able to display the bokeh app and table works well with sliders
Now the help needed is to add colour coding as shown in the picture attached

I answered on the other topic.

@bthat is okay
Could you help me make the download possible?

You can attach a callback to a button to run arbitrary Python code, and you have access to all the data and slider settings. You’ll have to use the settings and the data somehow to filter the the data (Pandas is good for this kind of thing) according to whatever criteria you have (which only know know). If the data won’t all fit in memory then you will have to process it in chunks. There’s not much more I can add, this is a general python question, or a python data processing questions, it isn’t really a Bokeh question.

1 Like

@Bryan Nice suggestion i shall try it thanks a lot