0

I am trying to select a country and based on the country i would like to display the count of restaurants on the dataset. I am not getting where i am missing the logic and the basic 2d graph is displaying before selecting the country using dropdown how can i avoid that. I have not missed any paranthesis or square braces and returned two outputs as it expects.

# import dash
from jupyter_dash import JupyterDash
import dash_core_components as dcc
import dash_table as dt
import dash_html_components as html
 
from dash.dependencies import Output, Input
from dash.exceptions import PreventUpdate
 
import plotly.graph_objs as go
 
#app = dash.Dash(__name__)
app = JupyterDash(__name__)


app.layout = html.Div(children = [
   html.H1('Data Analysis'),
   dcc.Dropdown(id='data-dropdown', options=[
       {'label': country, 'value': country.lower()} 
       for country in df1['Country'].unique()], placeholder= "Select Country"),
       dcc.Graph(id="CountGraph")
   ] , 
   id='container')
   
@app.callback([
   Output('data-dropdown', 'style'), Output('CountGraph', 'figure')],
   Input('data-dropdown', 'value'))
def multi_output(value):
   if value is None:
       raise PreventUpdate
   print(value)
   
   fig = px.histogram(df1[df1['Country']==value][value])

   style = {'backgroundColor' : '#24F50B' }
   return style, fig
 
 
if __name__ == '__main__':
   app.run_server(debug=True, mode="external")



df1.head(5).to_dict()

o/p:

{'Restaurant ID': {0: 6317637, 1: 6304287, 2: 6300002, 3: 6318506, 4: 6314302},
 'Restaurant Name': {0: 'Le Petit Souffle',
  1: 'Izakaya Kikufuji',
  2: 'Heat - Edsa Shangri-La',
  3: 'Ooma',
  4: 'Sambo Kojin'},
 'Country Code': {0: 162, 1: 162, 2: 162, 3: 162, 4: 162},
 'City': {0: 'Makati City',
  1: 'Makati City',
  2: 'Mandaluyong City',
  3: 'Mandaluyong City',
  4: 'Mandaluyong City'},
 'Address': {0: 'Third Floor, Century City Mall, Kalayaan Avenue, Poblacion, Makati City',
  1: 'Little Tokyo, 2277 Chino Roces Avenue, Legaspi Village, Makati City',
  2: 'Edsa Shangri-La, 1 Garden Way, Ortigas, Mandaluyong City',
  3: 'Third Floor, Mega Fashion Hall, SM Megamall, Ortigas, Mandaluyong City',
  4: 'Third Floor, Mega Atrium, SM Megamall, Ortigas, Mandaluyong City'},
 'Locality': {0: 'Century City Mall, Poblacion, Makati City',
  1: 'Little Tokyo, Legaspi Village, Makati City',
  2: 'Edsa Shangri-La, Ortigas, Mandaluyong City',
  3: 'SM Megamall, Ortigas, Mandaluyong City',
  4: 'SM Megamall, Ortigas, Mandaluyong City'},
 'Locality Verbose': {0: 'Century City Mall, Poblacion, Makati City, Makati City',
  1: 'Little Tokyo, Legaspi Village, Makati City, Makati City',
  2: 'Edsa Shangri-La, Ortigas, Mandaluyong City, Mandaluyong City',
  3: 'SM Megamall, Ortigas, Mandaluyong City, Mandaluyong City',
  4: 'SM Megamall, Ortigas, Mandaluyong City, Mandaluyong City'},
 'Longitude': {0: 121.027535,
  1: 121.014101,
  2: 121.056831,
  3: 121.056475,
  4: 121.057508},
 'Latitude': {0: 14.565443,
  1: 14.553708,
  2: 14.581404,
  3: 14.585318,
  4: 14.58445},
 'Cuisines': {0: 'French, Japanese, Desserts',
  1: 'Japanese',
  2: 'Seafood, Asian, Filipino, Indian',
  3: 'Japanese, Sushi',
  4: 'Japanese, Korean'},
 'Average Cost for two': {0: 1100, 1: 1200, 2: 4000, 3: 1500, 4: 1500},
 'Currency': {0: 'Botswana Pula(P)',
  1: 'Botswana Pula(P)',
  2: 'Botswana Pula(P)',
  3: 'Botswana Pula(P)',
  4: 'Botswana Pula(P)'},
 'Has Table booking': {0: 'Yes', 1: 'Yes', 2: 'Yes', 3: 'No', 4: 'Yes'},
 'Has Online delivery': {0: 'No', 1: 'No', 2: 'No', 3: 'No', 4: 'No'},
 'Is delivering now': {0: 'No', 1: 'No', 2: 'No', 3: 'No', 4: 'No'},
 'Switch to order menu': {0: 'No', 1: 'No', 2: 'No', 3: 'No', 4: 'No'},
 'Price range': {0: 3, 1: 3, 2: 4, 3: 4, 4: 4},
 'Aggregate rating': {0: 4.8, 1: 4.5, 2: 4.4, 3: 4.9, 4: 4.8},
 'Rating color': {0: 'Dark Green',
  1: 'Dark Green',
  2: 'Green',
  3: 'Dark Green',
  4: 'Dark Green'},
 'Rating text': {0: 'Excellent',
  1: 'Excellent',
  2: 'Very Good',
  3: 'Excellent',
  4: 'Excellent'},
 'Votes': {0: 314, 1: 591, 2: 270, 3: 365, 4: 229},
 'rupees': {0: 7062.0, 1: 7704.0, 2: 25680.0, 3: 9630.0, 4: 9630.0},
 'Country': {0: 'Philippines',
  1: 'Philippines',
  2: 'Philippines',
  3: 'Philippines',
  4: 'Philippines'}}
uma_8331
  • 89
  • 5
  • this line `fig = px.histogram(df1[df1['Country']=='India'][value])` looks strange – why are you hardcoding `India` if you're selecting the country using `value`? my guess would be that `fig = px.histogram(df1[df1['Country']==value])` makes more sense, but without knowing what `df1` looks like it's going to be hard to reproduce your problem or make suggestions. can you include a sample of `df1`? you can copy and paste the output from `df1.head(10).to_dict()` directly into your question, thank you – Derek O Jan 29 '23 at 22:47

0 Answers0