bertrandmartel / tableau-scraping

Tableau scraper python library. R and Python scripts to scrape data from Tableau viz
MIT License
131 stars 21 forks source link

Dashboards with dropdown box filters #7

Closed rexdouglass closed 3 years ago

rexdouglass commented 3 years ago

Hew Hampshire's COVID-19 dashboard has a dropdown box for filtering results to "County" https://www.nh.gov/covid19/dashboard/testing.htm#dash

It does not appear under selectables, parameters, or filters as best as I can find. Here's the output https://pastebin.com/raw/BNuVQrHn) for python prompt.py -get workbook -url "https://www.nh.gov/t/DHHS/views/COVID19TestingDashboard/TestingDashboard?:iid=4&:isGuestRedirectFromVizportal=y&:display_count=n&:showVizHome=n&:origin=viz_share_link"

Is this a use case you are aware of, and is there are part of tableau-scraper I should be using to handle it, perhaps in the "dashboards" part of the code?

bertrandmartel commented 3 years ago

@rexdouglass Hello, this seems to be a filter in the worksheet named "All Tests COVID19"

The following get the filters, iterate all the values of Union Key for CMN column (counties) and get the resulting worksheet All Tests COVID19 for each of them:

from tableauscraper import TableauScraper as TS

url = 'https://www.nh.gov/t/DHHS/views/COVID19TestingDashboard/TestingDashboard'
ts = TS()
ts.loads(url)

ws = ts.getWorksheet("All Tests COVID19")

filters = ws.getFilters()

counties = next(iter([
    t["values"]
    for t in filters
    if t["column"] == "Union Key for CMN"
]))
print(counties)

for county in counties:
    print(county)
    wb = ws.setFilter('Union Key for CMN', county)
    countyWs = wb.getWorksheet("All Tests COVID19")
    print(countyWs.data)

repl.it: https://replit.com/@bertrandmartel/TableauCovidNewHampshire

rexdouglass commented 3 years ago

Confirmed that does exactly what I need it to do. Thank you for your generous help and for an awesome package that's directly unlocking COVID data for research.