Black Lives Matter. Please consider donating to Black Girls Code today.

About dash_table.DataTable

Sorry in advance for this odd post.

Is this code dead, or am I not understanding how the filter function works? Is there some expanded explanation of this feature somewhere that is still valid?
EDIT: So not only do you need "eq " before the search term; it’s case sensitive. Sorry, case solved.

what I would prefer to do over that filter would be to make a dropdown, and then have that update the table, but I can’t find even two sources who agree how that should be done. Which makes me think that this is not the preferred path.

Here is some code to consider, and I would love a callback that updates my dash_table.DataTable based on the value. I see this other post, but I don’t understand how it would update a table.

{‘label’: i, ‘value’: i} for i in
value=‘Some string’

Can you leave out the value so you don’t have to have only a selection of your data shown at load?

TLDR; Some guy who has some understanding of Python + Pandas is struggling to understand dropdowns, callbacks, and the dash_table.DataTable due to inability to find any reasonable code examples or write ups. I am really hoping there is a better, fuller tutorial out there for the dash_table library.

It seems you’ve solved your specific problem? Or I’m not entirely sure what your problem is? I’m just going to give my opinion as a user who has made multiple applications with the Dash Table:

Firstly it’s in alpha and free so I cut it a lot of slack, also it’s very powerful compared to alternatives. But yeah the documentation currently sucks and you kind of need to have a good understanding of Dash and a bit of trial and error to get it to do any specific things you need.

The features are constantly improving but the filter “syntax” is kind of awful because you can not easily explain it to even fairly technical users. The ability to just simply filter based on if the filter string is a substring of the cell is desperately needed (same as how dash table experiment worked).

In the mean time for user facing filter queries I often just create a “filter” callback that takes an input as a textbox and an output as the data in the data-table. But this is somewhat limited because you can’t have multiple callbacks have the same output and you can’t always tell which input fired first when you have a callback with multiple inputs. Hopefully the regular syntax gets signficiantly improved in the coming months:

Also if you’re looking for a callback to update your datatable based on some other component like a dropdown it would look like this:

from dash.exceptions import PreventUpdate

@app.callback(output=dash.dependencies.Output('my-data-table', 'data'),
              inputs=[dash.dependencies.Input('my-dropdown', 'value')])
def update_table(dropdown_value):
    if not dropdown_value:
        raise PreventUpdate

    ... # do stuff with dataframe based on dropdown_value

    return df.to_dict("rows")

That may or may not help!

I totally get it, that it’s a passion project and young, but it was just striking how all-over-the-place people seem to be on how to handle problems like tables and updating those tables. Your concept here wasn’t present in any other code I’ve seen on the subject; which kind of proves the point. Coming from Python where there is one “blessed” (Pythonic) way of handling problems it’s just odd. So that’s where I am coming from. I don’t say it as a disrespect or belittling thing, it just makes it hard to know how stuff is meant to be used, or what the developers of the libraries intended them to be used for, or how they envision them all working together. And that’s what I was hoping to find; one unified vision for how to handle these problems within the “dash universe,” as I’ll call it. :grin:

Once I stopped trying to make the dash_table work it went real fast. I ended up making an HTML table and have a dropdown that fires some filtering on the dataframe object ( which I saw people calling dff in a couple instances of code, so I caught that) and then calls my HTML table making function with that dff. Just spit out the table, if the dropdown value is “all” (which is what I set the value to within the dropdown’s code) then just call the table generator on df, otherwise do the filter and kick out the dff based table.

I seriously appreciate the thoughtful reply and code though! I hadn’t seen PreventUpdate. I imagine that coming in handy down the road.

I am still looking for the preferred method for allowing a user to download the selected dataTable’s (or HTML table’s) contents as a CSV file. If you had any code examples for that, I’d love to see them. Thanks again for the reply.