question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Save multiple charts with same selenium instance

See original GitHub issue

One of the benefits that lead me to altair was the ability to generate vega-lite json that can be used in the to generate and save charts locally and in the browser. I’ve been able to save via the browser and locally.

Viewing and saving in the browser is nice for single charts. Saving locally is nice for saving a lot of charts programically (~50 charts). When saving locally altiar launches a selenium instance and a session to render and save the chart. This can be a little slow.

To reuse the selenium resources as much as possible, is there a way I can save multiple charts at once? Something like this would satisfy my desire for a small speed increase:

alt.save(*chart_list)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
jakevdpcommented, Jan 14, 2020

This is now implemented automatically in http://github.com/altair-viz/altair_saver. I plan to remove all selenium-based code from Altair itself, and require installation of altiar_saver for programmatic saving of PNG, SVG, and PDF.

0reactions
ehudkrcommented, Jan 14, 2020

Apologies for waking up this thread, but since no solution was implemented in altair yet (as far as I can tell), I would like to point out that there’s a good opportunity to get two scoops in one cone here. I propose allowing Chart.save() to receive an initialized selenium webdriver instance instead of a string. This way one can reuse the same webdriver over multiple saves, avoiding the overhead of save() initializing a new one each time:

from selenium import webdriver
driver = webdriver.Chrome()
# Generate altair charts...
for i, chart in enumerate(chart_list):
    chart.save(f"chart_{i}", webdriver=driver)

I think this might be a cleaner solution (API-wise) from altair’s point of view, as it avoids complicated user inputs, such as specifying lists/tuples of charts, file-names, and keyword-arguments.

As for the two-for-one: The other benefit of such a solution is that it also solves https://github.com/altair-viz/altair/issues/1619 and allows users greater freedom in how they set their work environment (for example, working on remote machines where one may not have permissions to PATH or /bin in order to point to webdriver executables. Users can specify arbitrary locations when initializing the driver: webdriver.Chrome('path/to/webdriver.exe)).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to scrape multiple pages using Selenium in Python?
Here, In this article, we are going to discuss how to scrap multiple pages using selenium. There can be many ways for scraping...
Read more >
📶 Chart Maker - SeleniumBase Docs
SeleniumBase ChartMaker lets you use Python to generate HTML charts. (Click to see a presentation with multiple charts). Here's how to run a...
Read more >
Altair automatic save chart using selenium chromedriver
With it, you can pass a custom driver instance to the save method: ... save(chart, "chart.png", method='selenium', webdriver=driver).
Read more >
Automate Complex Graphs with Selenium - YouTube
In this video, I have explained how to automate complex Graphs with SVG elements.~~~Subscribe to this channel, and press bell icon to get ......
Read more >
Automating report generation using Selenium Webdriver
If you need to automate the generation of chart images or PDF, Selenium Webdriver might be the best option. It can handle different...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found