question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`datestartswith` requires stringified date instead of just a date

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
chriddypcommented, Apr 26, 2019

Right yeah, {temperature} * 9 / 5 - 32 > 0 or w/e

0reactions
alexcjohnsoncommented, Apr 26, 2019

Not so useful in that exact case (arithmetic with literals) but if one part of the expression is a field you could do lots of cool things

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Issues with Date() when using JSON.stringify() and ...
It's just basic math but I seem to have some issues with that while using JSON.stringify() and JSON.parse() . If you're wondering why...
Read more >
Working with datetime as string - MongoDB
Let's say some external component inserts data into my database, with a field called “startDate”. They store this value as an ISO 8601 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found