From 7f8dc7236ddfbb5e143778c56f25e4c1579bb581 Mon Sep 17 00:00:00 2001 From: seangreaves Date: Sat, 7 Jan 2023 17:31:58 +0000 Subject: [PATCH] added download button to dashboard --- Procfile | 2 +- assets/networks/.DS_Store | Bin 6148 -> 0 bytes dashboard/Sugartrail.ipynb | 36 ++++++++++++++++++++++++++++++++---- sugartrail/base.py | 4 ++-- 4 files changed, 35 insertions(+), 7 deletions(-) delete mode 100644 assets/networks/.DS_Store diff --git a/Procfile b/Procfile index d39493f..a7be18c 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: voila --port=$PORT --no-browser --Voila.ip=0.0.0.0 dashboard/Sugartrail.ipynb --VoilaConfiguration.file_whitelist="['favicon.ico']" +web: voila --port=$PORT --no-browser --Voila.ip=0.0.0.0 dashboard/Sugartrail.ipynb --VoilaConfiguration.file_whitelist="['.*']" diff --git a/assets/networks/.DS_Store b/assets/networks/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "'''\n", + "\n", "def generate_map():\n", " map_data,path_table = mapview.build_map(network, clear_widget=False) \n", " hbox_map = widgets.HBox([path_table])\n", @@ -229,8 +241,14 @@ " with tab.children[2]:\n", " display(pd.DataFrame(network.officer_ids))\n", " with tab.children[3]:\n", - " display(pd.DataFrame(network.companies)) \n", + " display(pd.DataFrame(network.companies))\n", + " file = str(company_text.value) + '.json'\n", + " network.save(file, \"./\")\n", + " html_button = html_buttons.format(filename=file)\n", + " with download_link:\n", + " display(HTML(html_button))\n", "\n", + "download_link = widgets.Output()\n", "display(build_map_button, map_container)" ] }, @@ -253,6 +271,16 @@ "source": [ "accordion_data" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9224dce5", + "metadata": {}, + "outputs": [], + "source": [ + "download_link" + ] } ], "metadata": { diff --git a/sugartrail/base.py b/sugartrail/base.py index 65e0476..6d222ca 100644 --- a/sugartrail/base.py +++ b/sugartrail/base.py @@ -92,10 +92,10 @@ class Network: else: print("No input provided. Please provide either officer_id, company_id or address value as input.") - def save(self, filename): + def save(self, filename, location='../assets/networks/'): network_data = {k: v for k, v in self.__dict__.items() if k != 'hop' and k != 'file'} saved_network = json.dumps(network_data) - f = open(f'../assets/networks/{filename}', 'w') + f = open(f'{filename}', 'w') f.write(saved_network) f.close