python vincent needing url address

118 views Asked by At

I'm using vincent a data visualization package. One of the inputs it takes is path to data.

(from the documentation)

     `geo_data` needs to be passed as a list of dicts with the following
 |      format:
 |      {
 |          name: data name
 |          url: path_to_data,
 |          feature: TopoJSON object set (ex: 'countries')
 |      }
 |   

I have a topo.json file on my computer, but when I run that in, ipython says loading failed.

map=r'C:\Users\chungkim271\Desktop\DC housing\dc.json'
geo_data = [{'name': 'DC',
             'url': map,
             'feature': "collection"}]
vis = vincent.Map(geo_data=geo_data, scale=1000)
vis

Do you know if vincent only takes url addresses, and if so, what is the quickest way i can get an url address for this file?

Thanks in advance

2

There are 2 answers

0
krvkir On

It seems that you're using it in Jupyter Notebook. If no, my reply is irrelevant for your case.

AFAIK, vincent needs this topojson file to be available through web server (so javascript from your browser will be able to download it to build the map). If the topojson file is somewhere in the Jupyter root dir then it's available (and you can provide relative path to it), otherwise it's not.

To determine relative path you can use something like this:

import os
relpath = os.path.relpath('abs-path-to-geodata', os.path.abspath(os.path.curdir))
0
MissBleu On

I know that this post is old, hopefully this helps someone. I am not sure what map you are looking for, but here is the URL for the world map

world_topo="https://raw.githubusercontent.com/wrobstory/vincent_map_data/master/world-countries.topo.json"

and the USA state maps

state_topo = "https://raw.githubusercontent.com/wrobstory/vincent_map_data/master/us_states.topo.json"

I got this working beautifully, hope this is helpful for someone!