-
Notifications
You must be signed in to change notification settings - Fork 793
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
Open charts in the default browser with open_editor
method
#3358
Conversation
altair/vegalite/v5/api.py
Outdated
@@ -1104,24 +1104,31 @@ def to_html( | |||
**kwargs, | |||
) | |||
|
|||
def to_url(self, *, fullscreen: bool = False) -> str: | |||
def to_url(self, *, open_browser: bool = True, fullscreen: bool = False) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This technically breaks if someone used to rely on fullscreen as a positional argument via to_url(True)
. I don't think it's a huge deal, but also have nothing against reversing the order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thing is that thanks to the *
, fullscreen
has always been a keyword-only argument so this should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why we should lean towards kwarg-only APIs when we have the choice :) yay thanks past us
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool, I haven't come across this use of *
to block additional positional args. Thanks for linking the pep!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same! I use VS Code a lot and often use .to_url
to debug a spec in the Vega Editor. I'm fine with keeping it simple and having open_browser=True
as the default. I can't think of another use case for the to_url
method but maybe we're missing something?
@joelostblom Could you also add a note in the changelog?
Code looks good to me. Let's see if anyone else has an opinion on this before merging.
Thanks for the PR @joelostblom, I'm glad the I think I'm -1 on overloading So, I'd suggest adding a new top-level chart method named something like |
I think I agree with @jonmmease , I'm -.5 on this. Would it be way too clever if we made it so that to_url() returned a class VegaUrl(str):
def open(self): ... ? This is similar to what some SQL libraries do, they return an object that ducks like a str, but has some additional features. Using this would look like |
Thanks for the input everyone!
All great points. I was initially thinking that it seemed unnecessary with yet another method, but after considering what you wrote I think it makes more sense to go down that path. I don't have a strong preference between
Yup, will do! |
Good points, now I'm also in favour of putting it into a new method :) I like the custom string classes in SQL libraries! However, I'm not sure if in Altair we'd have a use case other than this for it so it might be a bit unexpected to users and a simple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the "Approve" for now as there seems a consensus to use a different method than to_url
I prefer |
Thanks for the input everyone. I also have a slight preference for |
LGTM! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. Could you update the PR title?
Regarding testing, we could do something clever with monkey patching the webbrowser
module. But this is so simple I don't think it's necessary.
to_url
open_editor
method
@binste Just a ping in case you wanted to have a second look too; otherwise I'm fine to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you @joelostblom!
I have been working more in VS Code instead of JupyterLab lately and really come to appreciate the
to_url()
method added in #3252 (thanks @jonmmease!). VS Code can't correctly handle the Vega-Lite actions menu #2875 and there seems to be little hope of fixing this microsoft/vscode-jupyter#13261.However, after trying to troubleshoot a few altair specs in the Vega-Lite window, I find myself copying the url over and over again after small edits to the altair spec (for me VS Code only sometimes figures out that the url is a link that can be clicked; maybe related to the length of the spec). It would be convenient if the Vega-Lite spec of the charts could automatically open in the default browser, which is what this PR tries to implement (also mentioned in #3252 (comment)).
I put the browser launch as the default when using
to_url()
, since I imagine that the most common scenario is to quickly go between the local editor and the online Vega-Editor to troubleshoot a spec. I find this convenient, but if it is considered too aggressive, then I'm happy to change it.Tagging everyone who was involved in the previous PR discussion: @jonmmease @NickCrews @mattijn @binste