1

I took a look at the Dash Module for python. I am trying to create a dashboard where I could select different values and have the volume of rows associated to the selection.

I get this error message volumetrie() missing 1 required positional argument. I couldn't find the problem. The code is fine when it's separate.

Please, do you have any idea to solve this ?

import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd

app = dash.Dash()

table=pd.read_csv('xxxxx.csv',
                    sep=';', low_memory=True, memory_map=True)


app.layout = html.Div([
    html.H1(children='The Segments Project'),

html.Div(children='''
    Interactive Dashboard.
    '''),                   

html.Label('Coupons Activity - Activity Size'),
dcc.Dropdown(
    id='vCoupon_Activity_Size',
    options=[
        {'label': 'Never Used', 'value': 'Never Used'},
        {'label': 'Small', 'value': 'Small'},
        {'label': 'Medium', 'value': 'Medium'},
        {'label': 'Large', 'value': 'Large'},
        {'label': 'X-Large', 'value': 'X-Large'}
    ],
    value='Small'
),

html.Label('Coupons Activity - Prints Regularity'),
dcc.Dropdown(
    id='vCoupon_Activity_Prints_Regularity',
    options=[
        {'label': 'Inactive', 'value': 'Inactive'},
        {'label': 'Offline_Only', 'value': 'Offline_Only'},
        {'label': 'Churner', 'value': 'Churner'},
        {'label': 'Regular-', 'value': 'Regular-'},
        {'label': 'Regular', 'value': 'Regular'},
        {'label': 'Regular+', 'value': 'Regular+'},
        {'label': 'TopRegular', 'value': 'TopRegular'}
    ],
    value='Regular'
),

html.Label('Coupons Activity - Usage Regularity'),
dcc.Dropdown(
    id='vCoupon_Activity_Usage_Regularity',
    options=[
        {'label': 'Inactive', 'value': 'Inactive'},
        {'label': 'Offline_Only', 'value': 'Offline_Only'},
        {'label': 'Churner', 'value': 'Churner'},
        {'label': 'Regular-', 'value': 'Regular-'},
        {'label': 'Regular', 'value': 'Regular'},
        {'label': 'Regular+', 'value': 'Regular+'},
        {'label': 'TopRegular', 'value': 'TopRegular'}
    ],
    value='Regular'
),

html.Label('Coupons Activity - Converter Type'),
dcc.Dropdown(
    id='vCoupon_Activity_Converter_Type',
    options=[
        {'label': 'Offline_Only', 'value': 'Offline_Only'},
        {'label': 'Never Converted', 'value': 'Never Converted'},
        {'label': 'Small', 'value': 'Small'},
        {'label': 'Medium', 'value': 'Medium'},
        {'label': 'High', 'value': 'High'},
        {'label': 'Multicanal User', 'value': 'Multicanal User'}
    ],
    value='Regular'
),

html.Label('Gender'),
dcc.Dropdown(
    id='vCRM_Activity_Gender',
    options=[
        {'label': 'Female', 'value': 'Female'},
        {'label': 'Male', 'value': 'Male'},
        {'label': 'Unknown', 'value': 'Unknown'}
    ],
),

html.Label('CRM Activity - User Type'),
dcc.Dropdown(
    id='vCRM_Activity_User_Type',
    options=[
        {'label': 'Exclusive Print', 'value': 'Exclusive Print'},
        {'label': u'Multichannel', 'value': 'Multichannel'},
        {'label': 'Exclusive Web', 'value': 'Exclusive Web'}
    ],
    value='Multichannel'
),   

html.Div(id='output-volumetrie')

], style={'columnCount': 2})


@app.callback(
              dash.dependencies.Output('output-volumetrie','children'),
              [dash.dependencies.Input('vCRM_Activity_User_Type','value'),
               dash.dependencies.Input('vCRM_Activity_Gender','value'),
               dash.dependencies.Input('vCoupon_Activity_Converter_Type','value'),
               dash.dependencies.Input('vCoupon_Activity_Usage_Regularity','value'),
               dash.dependencies.Input('vCoupon_Activity_Prints_Regularity','value'),
               dash.dependencies.Input('vCoupon_Activity_Size','value')])

def volumetrie(table,vCRM_Activity_Gender='All',
       vCRM_Activity_User_Type='All',vCoupon_Activity_Converter_Type='All',vCoupon_Activity_Prints_Regularity='All',
       vCoupon_Activity_Usage_Regularity='All',vCoupon_Activity_Size='All'):

def filtre(table,vCRM_Activity_Gender,
       vCRM_Activity_User_Type,
       vCoupon_Activity_Converter_Type,
       vCoupon_Activity_Prints_Regularity,
       vCoupon_Activity_Usage_Regularity,
       vCoupon_Activity_Size):

    if vCoupon_Activity_Size!='All' : condition1=(table['Coupon_Activity_Size']==vCoupon_Activity_Size)
    else: condition1=True

    if vCoupon_Activity_Prints_Regularity!='All' : condition2=(table['Coupon_Activity_Prints_Regularity']==vCoupon_Activity_Prints_Regularity)
    else : condition2=True

    if vCoupon_Activity_Usage_Regularity!='All' : condition3=(table['Coupon_Activity_Usage_Regularity']==vCoupon_Activity_Usage_Regularity)
    else : condition3=True

    if vCoupon_Activity_Converter_Type!='All' : condition4=(table['Coupon_Activity_Converter_Type']==vCoupon_Activity_Converter_Type)
    else : condition4=True

    if vCRM_Activity_Gender!='All' : condition5=(table['CRM_Activity_Gender']==vCRM_Activity_Gender)
    else: condition5=True

    if vCRM_Activity_User_Type!='All' : condition6=(table['CRM_Activity_User_Type']==vCRM_Activity_User_Type)
    else : condition6=True


    res=table[condition1 & condition2 & condition3 & condition4 & condition5 & condition6]

    return(res)

return(len(filtre(table,vCRM_Activity_Gender,
   vCRM_Activity_User_Type,vCoupon_Activity_Converter_Type,


    vCoupon_Activity_Prints_Regularity,vCoupon_Activity_Usage_Regularity,vCoupon_Activity_Size)))



if __name__ == '__main__':
    app.run_server(debug=True)
2
  • The code, as it is, will not run Commented Apr 23, 2018 at 19:11
  • I found my mistake Commented Apr 24, 2018 at 10:23

1 Answer 1

1

The mistake I made is to put the volumetrie function with the callback. This code is now working.

import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd

app = dash.Dash()

table=pd.read_csv(xxxxx.csv)

def volumetrie(vCoupon_Activity_Usage_Regularity,vCoupon_Activity_Prints_Regularity,vCoupon_Activity_Size,
               vCoupon_Activity_Converter_Type):  

    if (vCoupon_Activity_Usage_Regularity!='All' and vCoupon_Activity_Prints_Regularity!='All'  and
        vCoupon_Activity_Size!='All'  and vCoupon_Activity_Converter_Type!='All' ):
        res=table    

    else:            
        if vCoupon_Activity_Usage_Regularity!='All' : condition1=(table['Coupon_Activity_Usage_Regularity']==vCoupon_Activity_Usage_Regularity)
        else : condition1=True
        if vCoupon_Activity_Prints_Regularity!='All' : condition2=(table['Coupon_Activity_Prints_Regularity']==vCoupon_Activity_Prints_Regularity)
        else : condition2=True
        if vCoupon_Activity_Size!='All' : condition3=(table['Coupon_Activity_Size']==vCoupon_Activity_Size)   
        else : condition3=True
        if vCoupon_Activity_Converter_Type!='All' : condition4=(table['Coupon_Activity_Converter_Type']==vCoupon_Activity_Converter_Type)    
        else : condition4=True
        res=table[condition1 & condition2 & condition3 & condition4]
        return(len(res))

app.layout = html.Div([
    html.H1(children='The X Project'),

    html.Div(children='''
        Your Data Visualization Tool.
        '''),                   

    html.Label('Coupons Activity - Usage Regularity'),
        dcc.RadioItems(
            id='vCoupon_Activity_Usage_Regularity',
            options=[
                {'label': 'All', 'value': 'All'},
                {'label': 'Inactive', 'value': 'Inactive'},
                {'label': 'Offline_Only', 'value': 'Offline_Only'},
            ],
            value='All'
        ),
    html.Label('Coupons Activity - Prints Regularity'),
        dcc.RadioItems(
            id='vCoupon_Activity_Prints_Regularity',
            options=[
                {'label': 'All', 'value': 'All'},
                {'label': 'Inactive', 'value': 'Inactive'},
                {'label': 'Offline_Only', 'value': 'Offline_Only'},
                {'label': 'Churner', 'value': 'Churner'},
            ],
            value='All'
        ),
    html.Label('Coupons Activity - Activity Size'),
        dcc.RadioItems(
            id='vCoupon_Activity_Size',
            options=[
                {'label': 'All', 'value': 'All'},
                {'label': 'Large', 'value': 'Large'},
                {'label': 'X-Large', 'value': 'X-Large'}
            ],
            value='All'
    ),
    html.Label('Coupons Activity - Converter Type'),
        dcc.RadioItems(
            id='vCoupon_Activity_Converter_Type',
            options=[
                {'label': 'All', 'value': 'All'},
                {'label': 'Offline_Only', 'value': 'Offline_Only'},
                {'label': 'Never Converted', 'value': 'Never Converted'},
                {'label': 'Small', 'value': 'Small'},
                {'label': 'Medium', 'value': 'Medium'},
                {'label': 'High', 'value': 'High'},
                {'label': 'Multicanal User', 'value': 'Multicanal User'}
            ],
            value='All'
    ),


    html.Hr(),
    html.Div('Volume'),
    html.Div(
         id='output'
         )

], style={'columnCount': 1})


@app.callback(dash.dependencies.Output('output','children'),
              [dash.dependencies.Input('vCoupon_Activity_Usage_Regularity','value'),
               dash.dependencies.Input('vCoupon_Activity_Prints_Regularity','value'),
                dash.dependencies.Input('vCoupon_Activity_Size','value'),
                dash.dependencies.Input('vCoupon_Activity_Converter_Type','value')])   
def output1(vCoupon_Activity_Usage_Regularity,vCoupon_Activity_Prints_Regularity,vCoupon_Activity_Size,
            vCoupon_Activity_Converter_Type):   
    vol=volumetrie(vCoupon_Activity_Usage_Regularity,vCoupon_Activity_Prints_Regularity,vCoupon_Activity_Size,
                   vCoupon_Activity_Converter_Type)
    return vol


app.config.supress_callback_exceptions = True

if __name__ == '__main__':
    app.run_server(debug=True)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.