nbstata icon indicating copy to clipboard operation
nbstata copied to clipboard

Browse Functionality

Open cocopops17 opened this issue 2 years ago • 9 comments

Is it possible to get "browse" to work as it did with stata_kernel (i.e. open Stata's native browser in a new window)? I'm still using the Hydrogen package in Atom to run my code, so the currently-implemented %browse magic doesn't work for me.

cocopops17 avatar Feb 23 '23 17:02 cocopops17

In short: it may be possible, but it looks to be pretty involved, if so.

Stata's pystata api doesn't allow for it. So we'd have to try the completely separate route of Stata Automation that stata_kernel uses--and I'm not sure that separate approach can be made to play nicely with pystata.

To confirm my understanding, are you using Windows, or MacOS? If Windows, you did that extra install step for stata_kernel, right?

Currently, I'm only vaguely familiar with how this part of stata_kernel works, so it would be a steep climb for me to attempt adding this functionality personally. I'd be quick to pull it in if someone else codes it, though.

Another possibility would be to petition StataCorp to add this functionality to pystata, but I'm not sure they will see that as in their interest.

I'd also really like to have this feature. In practice, I myself currently go back and forth between working in Jupyter Lab and the normal Stata application, largely to be able to use browse. As long as the data you're working with isn't too big, it is relatively quick to save a .dta file in the notebook and then open it in normal Stata. But it would be really nice to streamline that workflow further somehow.

%head and %tail should work for you, at least, though I recognize they are nowhere near the same. (Another imperfect substitute: there may be a way to get nbstata's %browse plug-in to work with Atom, maybe starting from here, but that's definitely beyond my own aspirations.)

hugetim avatar Feb 23 '23 20:02 hugetim

This is also my biggest gripe with using Jupyter Notebooks for Stata with the current pystata API, which prevents me from fully embracing the workflow for exploratory analysis. @hugetim inspired by your call for petition, I posted this on Statalist.

In the meantime, I had experimented with various third-party data viewers for Python and I believe the best one is D-Tale. Would it ever be possible to have something like this integrated into %browse magic?

gaksaray avatar Feb 26 '23 12:02 gaksaray

Great, I'll go upvote you on Statalist!

And thanks for finding D-Tale! I think that looks better (and much easier to install) than the thing I had been using, so I expect I'll replace that with this very soon.

hugetim avatar Feb 26 '23 15:02 hugetim

Ok, I spent several hours trying to get D-tale to work reliably, and I couldn't. (And that's not even considering the difficulties campus folks would have trying to get it to work on JupyterHub.) Instead, I'm going with a much simpler and more robust option in ipydatagrid.

hugetim avatar Mar 08 '23 22:03 hugetim

But I'm thinking to add a %%python magic (someday) that would let you access dtale on your own if you want..

hugetim avatar Mar 09 '23 00:03 hugetim

I tried the new %browse magic in v0.5.0 and I like the fact that it's plain and requires no other packages to be installed. However, I experience sluggishness on my MacBook M1 (Safari). Please see the screen capture. Is this normal? I'd expect it to be buttery smooth as it's seemingly a very simple applet.

Also, two minor questions: Would it be possible to have an option to move this to a separate window (as in Data Editor in Stata)? And is it possible to change the font within the view (from Courier to something else)?

https://user-images.githubusercontent.com/72267919/224432250-ed3becac-b825-474e-a6ed-109bf9a267c5.mov

gaksaray avatar Mar 10 '23 21:03 gaksaray

Right click on it in JupyterLab and select "Create New View for Output." That gives you a separate tab within JupyterLab. But if you meant moving it to a separate browser tab, I don't know if that's possible.

On the sluggishness, I wasn't able to replicate that, trying it just now, so I'm not sure what to suggest. There's no sluggishness for me (albeit on a powerful Windows desktop, using Chrome).

I'm reluctant to change the default font because that's deliberately matching Stata's default look. I could make it configurable if that's important to you though. I guess maybe it's easier to see long strings with a different font?

hugetim avatar Mar 10 '23 21:03 hugetim

This is what I see on classic Notebook:

Screen Shot 2023-03-24 at 10 39 56 PM

There is no way to resize that browse window.

Then I switch to Lab. Datagrid looks fine, but the choppiness is real (mind you this is the tiny auto dataset):

https://user-images.githubusercontent.com/72267919/227656440-7fca20a7-b9fe-4c45-a5b5-47c2899a4841.mov

I'm on M1 Mac with macOS Monterey and Safari so I don't know if this is specific to Apple setup.

gaksaray avatar Mar 24 '23 22:03 gaksaray

As a workaround while we try to address those issues, you can use %head [N] or %tail [N] as an alternative to %browse (replacing [N] with a number at least as large as your observation count). That should give you output equivalent to pystata_kernel's %browse magic.

hugetim avatar Mar 25 '23 16:03 hugetim

Narrow %browse widget addressed by v0.8.1

hugetim avatar Oct 26 '24 02:10 hugetim

Are you still seeing choppiness, @gaksaray?

I think I'm done working on this for now, in any case. FYI, my longer-term plan is to work toward integration with Positron's Data Explorer: https://positron.posit.co/data-explorer.html But that may be a while, as Positron's extension API is still experimental and undocumented.

Also... is it possible to change the font within the view (from Courier to something else)?

v0.8.1 also changed the %browse font (in line with Stata 18's change).

hugetim avatar Oct 28 '24 17:10 hugetim