在 TSC 中应用过滤器后将画面视图导出为 pdf

export tableau view to pdf after applying filter in TSC

我正在尝试使用 python 画面服务器客户端导出画面视图。
以下是用于创建pdf的部分代码。

server.views.populate_pdf(view, options)

with file("dashboard.pdf", 'wb') as f:
    f.write(view.pdf)

此代码运行良好,正在将视图导出为 pdf 文件。
我的画面仪表板几乎没有过滤器(例如 product_type,供应商)。
如何在导出时添加视图筛选器,以便仅获取特定 product_type 和供应商的数据?

我想我使用以下示例找到了答案。
https://github.com/tableau/server-client-python/blob/master/samples/export.py
我们需要添加视图过滤器(vf)如下:

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

参考: https://github.com/tableau/server-client-python/blob/master/tableauserverclient/server/request_options.py#L90

准备好过滤器选项后,我们可以传递它来填充 pdf。

server.views.populate_pdf(view, options)
with file("dashboard.pdf", 'wb') as f:
    f.write(view.pdf)