Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

datestartswith requires stringified date instead of just a date #420

@chriddyp

Description

@chriddyp

I'd like to write {Date received} datestartswith 2015 but instead I have to write {Date received} datestartswith "2015"

Example:

import dash
from dash.dependencies import Input, Output
import dash_html_components as html
import dash_core_components as dcc
from dash_table import DataTable
import json
import pandas as pd
import textwrap


url = ("https://github.com/plotly/datasets/raw/master/"
       "26k-consumer-complaints.csv")

types = {
    'id': 'numeric',
    'ZIP code': 'text',
    'Date received': 'datetime',
    'Date sent to company': 'datetime',
}

df = pd.read_csv(url)
df['id'] = df['Unnamed: 0']
df = df.drop(['Unnamed: 0'], axis=1)
df = df.reindex(columns=['id']+df.columns[:-1].tolist())

app = dash.Dash(__name__)
app.scripts.config.serve_locally = True

app.layout = ddk.App([

    dcc.Textarea(
        id='filter-input',
        style={'width': '100%', 'height': '150px'},
        value='{id} > 5'
        # value=textwrap.dedent(
        # '''
        # {id} > 100 and
        # ({State} = TX or {State} = NJ) and
        # {Date received} = {Date sent to company} and
        # {Product} contains Debt and
        # {Date received} datestartswith "2015-02"
        # ''')
    ),

    dcc.RadioItems(
        id='output-type',
        options=[
            {'label': i, 'value': i} for i in ['Filter', 'Highlight']
        ],
        value='Highlight'
    ),

    html.Div(
        children=DataTable(
            id='demo-table',
            data=df.to_dict('rows'),
            columns=[{ 'id': i, 'name': i, 'type': types.get(i, 'any') } for i in df.columns],
            filtering=True,
            pagination_mode=False,
            virtualization=True,
            style_data={
                'width': '200px'
            },
            style_table={
                'height': 'calc(100vh - 200px)'
            }
        ),
    )
])

@app.callback(
    [Output('demo-table', 'filter'),
     Output('demo-table', 'style_data_conditional')],
    [Input('output-type', 'value'),
     Input('filter-input', 'value')])
def update_filter(output_type, value):
    value = value.strip()

    if output_type == 'Filter':
        return [value, []]
    else:
        return ['', [{
            'if': {
                'filter': value,
            },
            'backgroundColor': 'hotpink'
        }]]



if __name__ == "__main__":
    app.run_server(port=8080, debug=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions