问题
I am trying to export a tableau view using python tableau server client.
Following is the part of code which is used for creating pdf.
server.views.populate_pdf(view, options)
with file("dashboard.pdf", 'wb') as f:
f.write(view.pdf)
This code is working fine and it is exporting a view to pdf file.
My tableau dashboard has few filters(e.g. product_type, vendor).
How can I add a view filter while exporting so that I will only get data for specific product_type and vendor?
回答1:
I think I found the answer using following example.
https://github.com/tableau/server-client-python/blob/master/samples/export.py
We need to add view filters(vf) as follow:
option_factory = getattr(TSC, "PDFRequestOptions")
options = option_factory().vf("product_type","Handphone")
options.vf("vendor","vendor1")
#In case of multi select filter we can use coma separated values as followed
options.vf("vendor","vendor1,vendor2")
#To get the list of all filter options use
print options.view_filters
Reference: https://github.com/tableau/server-client-python/blob/master/tableauserverclient/server/request_options.py#L90
Once we have filter options ready we can pass it to populate pdf.
server.views.populate_pdf(view, options)
with file("dashboard.pdf", 'wb') as f:
f.write(view.pdf)
来源:https://stackoverflow.com/questions/53839824/export-tableau-view-to-pdf-after-applying-filter-in-tsc