Incorporating mask into app.callback for Dash

wanted to open by saying that I’m new to python (and to coding overall), so apologies if this question is bad.

I’m running into an issue using Dash. What I’m trying to do is create a Mask that returns True only for the firm the user has selected, however when I run the code I get no errors, but it sets every firm to be true, and whatever the user selects does nothing. What’s weird is that I have code that does essentially the same thing, and runs without issue. I’ve taken this code from the plotly documentation on building line charts, and edited it slightly to fit my needs.

I tried running the code below, and it returns a dashboard without error. Users are given a dropdown on which firm they want to display, and it should only display whichever firm (or firms) they’ve picked. However the graph it returns displays EVERY firm, and whatever the user picks doesn’t change the plotly figure displayed

     app = Dash('Affil Sales')

     app.layout = html.Div([
            html.H4('Affil vs Non-Affil price'),
            dcc.Graph(id = "graph"),
            dcc.Dropdown(
             id="dropdown",
             options= [
                {'label': i, 'value': i} for i in list(df2['z_seller_clean'].unique())],
             multi = True,
             placeholder = 'Select a firm'

        ),
      ])

Here I used “{‘label’: i, ‘value’: i} for i in list(df2[‘z_seller_clean’].unique())]” to set the options. There are to many firms listed to be able to write out manually. This works to create the dropdown

@app.callback(
   Output("graph", "figure"), 
    Input("dropdown", "value"))
 def update_line_chart(z_seller_clean):
       df3 = df2
       mask = df3.z_seller_clean.isin(list(df3['z_seller_clean'].unique())) # Remember df2[mask]
         fig1 = px.line(df3[mask], 
              x="TRADE_DATE", y="Z_PRICEINDOLPERMWH", color='Buyer_Is_Affiliate')
return fig1

app.run_server(debug=True)

This code runs, but it returns a graph with every firm displayed, How do I set up the mask function to actually work? If I remove the mask function, the code runs the exact same. The goal of the mask is to create a Boolean, it should return False for every firm not picked by the user, and return True for whatever firms have been picked. However it just returns True for every firm

I have another set of code that runs without issue, I’ll paste it below

   df_gb_q = df.groupby(['TRADE_DATE', 'Buyer_Is_Affiliate', 'Z_REGION'])[['Z_QUANTITYINMWH']].mean()

   df_gb_q.reset_index(inplace=True)


    app_region_mwh = Dash('Affil Sales')

        app_region_mwh.layout = html.Div([
           html.H4('Affil vs Non-Affil MWH'),
           dcc.Graph(id = "graph"),
           dcc.Checklist(
              id="checklist",
              options= ["Florida", "Northwest", "Southeast","Southwest"],
              value = ["Florida"],
              inline=True
       ),
      ])


    @app_region_mwh.callback(
          Output("graph", "figure"), 
          Input("checklist", "value"))
    def update_line_chart(Z_REGION):
          df_new_q = df_gb_q
           mask = df_new_q.Z_REGION.isin(Z_REGION)
           fig_q_reg = px.line(df_new_q[mask], 
                 x="TRADE_DATE", y="Z_QUANTITYINMWH", color='Buyer_Is_Affiliate')
      return fig_q_reg

app_region_mwh.run_server(debug=True)

This code creates a dashboard the runs without error, and only displays whatever is on the checklist (i.e whatever the user has picked)

New contributor

Aidan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật