export tableau view to pdf after applying filter in TSC

泪湿孤枕 提交于 2021-02-10 20:35:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!