Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exporting images/csvs/pdfs is returning None #1561

Closed
dannbannn opened this issue Jan 22, 2025 · 5 comments
Closed

exporting images/csvs/pdfs is returning None #1561

dannbannn opened this issue Jan 22, 2025 · 5 comments

Comments

@dannbannn
Copy link

Attempting to export view to an image however it keeps returning blank:

with sign_in:
    all_workbooks, _ = server.workbooks.get()
    print(f"Found {len(all_workbooks)} workbooks.")

    target_workbook = next(
        (workbook for workbook in all_workbooks if workbook.name == wb_name), None
    )

    if not target_workbook:
        print("Workbook not found.")
    else:
        print(f"Found workbook: {target_workbook.name}")

        server.workbooks.populate_views(target_workbook)
        target_view = next((view for view in target_workbook.views if view.name == view_name), None)

        if not target_view:
            print("View 'Dashboard 1' not found in the workbook.")
        else:
            print(f"Found view: {target_view.name}")
        
            image = server.views.populate_image(target_view)
            if image:
                with open("Dashboard1.png", "wb") as file:
                    file.write(image)
                print("Image exported successfully as 'Dashboard1.png'.")
            else:
                print("Image data is None")

returns

Found 51 workbooks.
Found workbook: test_emails
Found view: Dashboard 1
Image data is None

There is metadata for the view but any type of .populate() is returning nothing. There are no filters on the view or in the dashboard and I have full privileges to export.

Am I missing something?

@jorwoods
Copy link
Contributor

The populate methods populate the property on the item, rather than directly return the output. You retrieve the content from

view.pdf, view.csv, or view.image.

@dannbannn
Copy link
Author

Embarrassing. Thank you. Is there any documentation on this anywhere?

@jorwoods
Copy link
Contributor

Views.populate_image has an example. In newer versions of TSC, the functions should also have docstrings and typehints that indicate what the functions accept and return. There is an example export, but it might be too generalized to be able to pick up specifics like this.

@jorwoods
Copy link
Contributor

Also, be cautious with this syntax:

all_workbooks, _ = server.workbooks.get()
    print(f"Found {len(all_workbooks)} workbooks.")

    target_workbook = next(
        (workbook for workbook in all_workbooks if workbook.name == wb_name), None
    )

all_workbooks in this case would not in fact be ALL workbooks. It would only be the first page of workbooks, by default, 100.

I recommend looking at the docs for Page through Results as well as Filter and Sort for details. Personally, I prefer the Django style filtering.

@dannbannn
Copy link
Author

Very useful, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants