How can I extract values from Tableau dashboard

0 votes

I am trying to extract the "Company & Tests" values from this Web page: https://public.tableau.com/views/v_7_14_2020/COVID-19TestingCommons

The preferred output would be a array with company and number of tests for each company.

There is another thread (How can I scrape tooltips value from a Tableau graph embedded in a webpage) with a similar question..

I tried to work with that and it didn't work in my case

Thank You.

import requests 
from bs4 import BeautifulSoup
import json
import time

data_host = "https://public.tableau.com"

r = requests.get(
    f"{data_host}/views/v_7_14_2020/COVID-19TestingCommons",
    params= {
        ":showVizHome":"no",
    }
)
soup = BeautifulSoup(r.text, "html.parser")

tableauData = json.loads(soup.find("textarea",{"id": "tsConfigContainer"}).text)

dataUrl = f'{data_host}{tableauData["vizql_root"]}/bootstrapSession/sessions/{tableauData["sessionid"]}'


r = requests.post(dataUrl, data= {
    "sheet_id": tableauData["sheetId"],
})

dataReg = re.search('\d+;({.*})\d+;({.*})', r.text, re.MULTILINE)
info = json.loads(dataReg.group(1))
data = json.loads(dataReg.group(2))

print(data["secondaryInfo"]["presModelMap"]["dataDictionary"]["presModelHolder"] ["genDataDictionaryPresModel"]["dataSegments"]["0"]["dataColumns"])
Apr 8, 2022 in Tableau by Vaani
• 7,070 points
1,568 views

1 answer to this question.

0 votes

Your tableau address is using server side rendering in this situation. It means that no data is supplied to the browser by default, and the server renders visuals with the data (tables, maps, etc.). Selection events are triggered by JS sending mouse coordinates to the server.

However, utilising the filters, you can have some info rendered client-side in your situation. When you choose a filter, such as "specimen," the data is rendered on the client (actual data are sent to the browser).

To extract data from Tableau workbooks, I created a tableau scraper library. You may run the following code to import the tableau data (empty worksheets), get the filter in the Diagnostic Target called Specimen worksheet, and save it. Get the worksheet data for each of these by collecting and iterating each value of this filter:

from tableauscraper import TableauScraper as TS
import pandas as pd

url = "https://public.tableau.com/views/v_7_14_2020/COVID-19TestingCommons"

ts = TS()
ts.loads(url)
workbook = ts.getWorkbook()

ws = workbook.getWorksheet("Diagnostic Target")

specimens = [
    t["values"]
    for t in ws.getFilters()
    if t["column"] == "Specimen Collected"
][0]

pdList = []
for specimen in specimens:
    print(f"specimen: {specimen}")
    specResultWb = ws.setFilter("Specimen Collected", specimen)
    df = specResultWb.getWorksheet("Company and Tests").data
    pdList.append(df)

result = pd.concat(pdList, ignore_index=True)
print(result)

Ready to stand out in the world of data visualization? Explore our Tableau Certification Program and unlock a new realm of opportunities by validating your expertise in the industry's leading data visualization tool!

answered Apr 21, 2022 by Neha
• 9,020 points

Related Questions In Tableau

+2 votes
1 answer
0 votes
1 answer

How can I remove { } from columns in Tableau?

Create the following calculated field and use ...READ MORE

answered Aug 10, 2018 in Tableau by Atul
• 10,240 points
965 views
0 votes
1 answer

How can I automate publishing dashboard to Tableau server?

Getting data from excel to Tableau Server: Setup ...READ MORE

answered Oct 10, 2018 in Tableau by ffdfd
• 5,550 points
3,866 views
0 votes
1 answer

How can I use Tableau to create a heatmap?

Step 1: Create an Excel Spreadsheet with ...READ MORE

answered Apr 2, 2018 in Tableau by ffdfd
• 5,550 points
2,939 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,465 views
0 votes
1 answer
0 votes
1 answer

How can I convert a dimension into a measure in Tableau

I'd like to ask a technical question ...READ MORE

answered Apr 5, 2022 in Tableau by Neha
• 9,020 points
1,253 views
0 votes
1 answer

How can I automatically add pictures in Tableau Tooltip?

Another alternative is to utilise the Viz ...READ MORE

answered Apr 5, 2022 in Tableau by Neha
• 9,020 points
1,250 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP