इंटरैक्टिव बहु फिल्टर पानी का छींटा Plotly जीआईएस मानचित्र-- आंकड़ा काम नहीं कर रहा

0

सवाल

हैलो ढेर विनिमय,

मेरे जीवन के लिए मैं पता नहीं कर सकते कि मैं क्या कर रहा हूँ गलत है इस बिंदु पर है । मैं कर रहा हूँ एक शुरुआत प्रोग्रामर तो मैं गर्व कर रहा हूँ के यहाँ हो रही है; लेकिन अगर वहाँ अन्य समाधान है कि और अधिक प्रभावी रहे हैं, कृपया महसूस मुक्त करने के लिए सुझाव देते हैं ।

डेटा फ़ाइलें:

  • gdf_final_serial
  • ^यह एक संक्षिप्त संस्करण के रूप में वास्तविक डाटासेट है ~680K पंक्तियों
  • geo_school
  • ^Json इस्तेमाल किया जा रहा है

क्या मैं की जरूरत है पानी का छींटा अनुप्रयोग के लिए करते हैं:

  • काम के रूप में एक बहु फिल्टर जीआईएस मानचित्र के संबंध में खेतों में सूचीबद्ध (काउंटी, जिला का नाम, उम्र, फिर से, चतुर्थांश, आवास असुरक्षित)
  • फिल्टर पर आधारित चुना है, अद्यतन px.choropleth_mapbox के साथ सटीक गणना के 'अंक'.

चलो में कूद कोड. मैं भी हूँ पर यह चल रहा है एक गूगल Colab नोटबुक है ।

filename_1 = root_path+"schoolDistrictBoundaries_Fixed.json"
file = open(filename_1)
schoolDistricts = gpd.read_file(file)

^^ भागा जा रहा में एक वैश्विक सेल

import dash
import dash.dependencies
import plotly.express as px
import pandas as pd
from jupyter_dash import JupyterDash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objects as go
import numpy as np

px.set_mapbox_access_token(mapbox_access_token)

###   Creating gdf_final_serial

geo_df = gpd.GeoDataFrame.from_features(geo_school["features"]).merge(joined, on="OBJECTID").set_index("OBJECTID") #GeoJson Join to Joined Dataframe
cleaned_geo_df = geo_df[["geometry_x", "CountyName_x", "RE", "QUARTILES", "HOUSING_INSECURE", "County", "Age", "DistrictName_x"]] #Picks the right columns
geo_df_final = cleaned_geo_df.rename(columns={"CountyName_x": "CountyName", "geometry_x": "geometry", 'DistrictName_x': 'DistrictName'}) #Changing Column Names
geo_df_final.to_pickle(root_path+"geo_df_final") #Write to drive as a pickle to serialize
df_final_serial = pd.read_pickle(root_path+"geo_df_final") #Read as DataFrame
gdf_final_serial = gpd.GeoDataFrame(data = df_final_serial, geometry= "geometry", crs = "epsg:4326") #Turn into GeoPandas DataFrame and set the geometry and crs


re_indicators = gdf_final_serial.RE.unique()
county_indicators = gdf_final_serial.CountyName.unique()
age_indicators = gdf_final_serial.Age.unique()
district_indicators = gdf_final_serial.DistrictName.unique()

external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]
app = JupyterDash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div(
    [
        html.Div(
            children=[
                html.Label("County"),
                dcc.Checklist(
                    id="county",
                    options=[{"label": i, "value": i} for i in county_indicators],
                    value=[]
                ),
                html.Label("District Name"),
                dcc.Dropdown(
                    id="dname",
                    options=[],
                    value=[],
                    multi=True,
                ),
                html.Label("Age"),
                dcc.Dropdown(id="age", 
                             options=[], 
                             value=[],
                             multi = True),
                html.Label("RE"),
                dcc.Dropdown(id="re", 
                             options=[], 
                             value=[], 
                             multi = True),
                html.Label("Quartiles"),
                dcc.Dropdown(id="quartiles", 
                             options=[], 
                             value=[], 
                             multi=True),
                html.Label("Housing"),
                dcc.Dropdown(id="housing", 
                             options=[], 
                             value=[], 
                             multi=True),
                dcc.Graph(id="my_map", figure={})])
            ]
        )

@app.callback(
  dash.dependencies.Output("dname", "options"), 
  dash.dependencies.Input("county", "value")
)
def choose_county(county_pick): 
  if len(county_pick) > 0: 
      dff=gdf_final_serial[gdf_final_serial.CountyName.isin(county_pick)]
  else: 
      raise dash.exceptions.PreventUpdate
  return [{"label": i, "value": i} for i in (dff.DistrictName.unique())]

@app.callback(
  dash.dependencies.Output("dname", "value"),
  dash.dependencies.Input("dname", "options"),
)
def set_city_value(available_options_dname):
  return [x["value"] for x in available_options_dname]


@app.callback(
  dash.dependencies.Output("age", "options"), 
  dash.dependencies.Input("dname", "value")
)
def dname_age_picker(choose_dname):
  print(choose_dname)
  if len(choose_dname) > 0:
    dff = gdf_final_serial[gdf_final_serial.DistrictName.isin(choose_dname)]
  else:
    raise dash.exceptions.PreventUpdate
  return [{"label": i, "value": i} for i in (dff.Age.unique())]


@app.callback(
  dash.dependencies.Output("age", "value"),
  dash.dependencies.Input("age", "options"),
)
def set_age_value(available_options_age):
  return [x["value"] for x in available_options_age]


@app.callback(
  dash.dependencies.Output("re", "options"), 
  dash.dependencies.Input("age", "value")
)
def age_re_picker(choose_age):
  if len(choose_age) > 0:
    dff = gdf_final_serial[gdf_final_serial.Age.isin(choose_age)].dropna(axis = 0, how = 'any', subset = ["RE"])
  else:
    raise dash.exceptions.PreventUpdate
  return [{"label": i, "value": i} for i in (dff.RE.unique())]

@app.callback(
  dash.dependencies.Output("re", "value"),
  dash.dependencies.Input("re", "options")
)
def set_re_value(available_options_re):
  return [x["value"] for x in available_options_re]


@app.callback(
  dash.dependencies.Output("quartiles", "options"), 
  dash.dependencies.Input("re", "value")
)
def re_quartile_picker(choose_re_value):
  if len(choose_re_value) >= 0:
    dff = gdf_final_serial[gdf_final_serial.RE.isin(choose_re_value)].dropna(axis = 0, how = 'any', subset = ["QUARTILES"])
  else:
    raise dash.exceptions.PreventUpdate
  return [{"label": i, "value": i} for i in (dff.QUARTILES.unique())]

@app.callback(
  dash.dependencies.Output("quartiles", "value"),
  dash.dependencies.Input("quartiles", "options"),
)
def set_quart_value(available_options_quart):
  return [x["value"] for x in available_options_quart]

@app.callback(
  dash.dependencies.Output("housing", "options"), 
  dash.dependencies.Input("quartiles", "value")
)
def quart_picker(choose_quart_value):
  if len(choose_quart_value) >= 0:
      dff = gdf_final_serial[gdf_final_serial.QUARTILES.isin(choose_quart_value)]
  else:
      raise dash.exceptions.PreventUpdate
  return [{"label": i, "value": i} for i in (dff.HOUSING_INSECURE.unique())]

@app.callback(
  dash.dependencies.Output("housing", "value"),
  dash.dependencies.Input("housing", "options"),
)
def set_housing_value(available_options_housing):
  return [x["value"] for x in available_options_housing]

@app.callback(
  dash.dependencies.Output("my_map", "figure"),
  [dash.dependencies.Input("housing", "value"), 
  dash.dependencies.Input("quartiles", "value"), 
  dash.dependencies.Input("re", "value"),
  dash.dependencies.Input("age", "value"),
  dash.dependencies.Input("dname", "value"),
  dash.dependencies.Input("county", "value")]
)
def update_fig(selected_housing, selected_quartiles, selected_re, selected_age, selected_dname, selected_county):
  gdff_1 = gdf_final_serial[gdf_final_serial.CountyName.isin(selected_county) & 
                            gdf_final_serial.DistrictName.isin(selected_dname) &
                            gdf_final_serial.Age.isin(selected_age) &
                            gdf_final_serial.RE.isin(selected_re) &
                            gdf_final_serial.QUARTILES.isin(selected_quartiles) & 
                            gdf_final_serial.HOUSING_INSECURE.isin(selected_housing)]
  count_points = gdff_1.groupby("OBJECTID").size().rename("points")
  gdf_last = gdff_1.merge(count_points, on="OBJECTID", how="right", right_index = True)
  gdf_last.to_pickle(root_path+"gdf_last") #Write to drive as a pickle to serialize
  ddf_final_serial = pd.read_pickle(root_path+"gdf_last") #Read as DataFrame
  gddf_final_serial = gpd.GeoDataFrame(data = ddf_final_serial, geometry= "geometry", crs = "epsg:4326")
  gdff_2 = gddf_final_serial.head(50)
  px.set_mapbox_access_token(mapbox_access_token)
  fig = px.choropleth_mapbox(data_frame= gdff_2,
                             geojson= geo_school,
                             locations= 'DistrictName',
                             featureidkey = 'properties.DistrictName',
                             color="points",
                             center={"lat": 38.5941, "lon": -119.8815}, 
                             mapbox_style = 'dark').update_layout(mapbox_accesstoken =  mapbox_access_token)
  return fig
# Run app and display result inline in the notebook
if __name__ == "__main__":
  app.run_server(host="127.0.0.1", port="8888",debug=True, use_reloader=False)

मैं सक्षम किया गया है प्राप्त करने के लिए विभिन्न स्थितियों, जहां नक्शा/फिल्टर का उत्पादन होगा एक एकल काउंटी, कभी कभी दो काउंटियों-लेकिन कभी नहीं पूरा मामला. रखने के मन में अपने अंतिम लक्ष्य बनाने के लिए है के लिए इस पूरे डाटासेट (शायद का उपयोग कर RapidsAI से NVIDIA; हालांकि मैं कर रहा हूँ स्थापित करने में परेशानी है कि के रूप में अच्छी तरह से गूगल के भीतर Colab).

क्या अधिक है दिलचस्प है कि जब मैं इस कोड को चलाने के बाहर पानी का छींटा के रूप में (एक नमूना के लिए वास्तविक डेटासेट) और इसे पारित करने के लिए अंजीर.शो(), यह दिखा देंगे; तथापि, यह काम नहीं करेगा में पानी का छींटा अनुप्रयोग है ।

मुझे संदेह है कि समस्या है या तो के साथ json से निपटने या अंतिम कॉलबैक के रूप में डिबगर इंगित करता है कि जबकि आदानों कर रहे हैं, my_map.आंकड़ा नहीं है outputting डेटा. मैं मदद की सराहना करते हैं.

bigdata gis json plotly-dash
2021-11-24 02:35:43
1

सबसे अच्छा जवाब

0
  1. यह कठिन है करने के लिए असंभव वर्तमान में आप क्या चाहते हैं में Colab क्योंकि साजिश है । ly पानी का छींटा चला जाएगा inlineहै , लेकिन नहीं के रूप में एक पानी का छींटा app dashboard उपयोग के कारण प्रतिबंध Colab वर्तमान में है के लिए अपने उदाहरण. आप का उपयोग किया जाना चाहिए रैपिड्स स्थापित टेम्पलेट के लिए Colab, btw.
  2. हम कुछ काम करने के लिए इसी तरह की क्या तुम पर काम कर रहे हैं, में तैनात paperspace. हम बनाया एक रैपिड्स आधारित ट्यूटोरियल. आप भी कर सकते हैं कोड को ले जाओ और इसे तैनात कहीं और, यदि आप चाहते हैं.
2021-11-24 20:30:46

अन्य भाषाओं में

यह पृष्ठ अन्य भाषाओं में है

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

इस श्रेणी में लोकप्रिय

लोकप्रिय सवाल इस श्रेणी में