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

San*_*esh 2 python tableau-api

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

server.views.populate_pdf(view, options)

with file("dashboard.pdf", 'wb') as f:
    f.write(view.pdf)
Run Code Online (Sandbox Code Playgroud)

这段代码工作正常,它正在将视图导出到 pdf 文件。
我的 Tableau 仪表板几乎没有过滤器(例如产品类型、供应商)。
如何在导出时添加视图过滤器,以便仅获取特定产品类型和供应商的数据?

San*_*esh 5

我想我用下面的例子找到了答案。
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
Run Code Online (Sandbox Code Playgroud)

参考: 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)
Run Code Online (Sandbox Code Playgroud)