sassoftware / saspy

A Python interface module to the SAS System. It works with Linux, Windows, and Mainframe SAS as well as with SAS in Viya.
https://sassoftware.github.io/saspy
Other
367 stars 149 forks source link

SASMagic command changes Notebook style/theme #535

Closed Debbby57 closed 1 year ago

Debbby57 commented 1 year ago

Describe the bug Hello Tom, I'm working with Visual Studio Code. I configured the Dark Theme. I created a jupyter notebook and used the SASMagic command. As soon as I execute a SAS Code, it changes the style of outputs in the whole notebook and I can't get back to my previous theme.

my_session= saspy.SASsession()
%%SAS my_session
proc print data=my_table;
run;

To Reproduce Steps to reproduce the behavior:

  1. use a specific theme in jupyter notebook (vscode theme)
  2. execute some python code with ouputs
  3. launch a sas session and use %%SAS command and execute some sas code with output

Expected behavior I can understand the SASMagic needs to format its results but it must not change all notebook's outputs.

Screenshots before %%SAS image %%SAS image after %%SAS command execution image

Thanks for your help :)

tomweber-sas commented 1 year ago

Hey, do you know what version of Notebook you're running? I remember older version of it having issues like that where the whole web page changed when it rendered an html image. But that got better over time. Jupyter Lab is their newer version, and I'm not sure how much support goes into Notebook any more. I tried this with Lab (it had a dark theme) and I didn't see any of it change when I rendered an image. The version of Notebook I have installed doesn't have any of these themes, so I'll have to figure out how to install some to really try it. Though I didn't see it change like it used to (years ago) with the older versions.

SASPy doesn't 'do' anything or have any control of anything in Jupyter. All that's happening is SAS returns an HTML document which Jupyter renders in it's web page. How they do that is where this kind of cross interaction ends up happening. Do you think you can upgrade Notebook to the latest, or try Lab to see if it behaves better? I'll try to install some themes to my version of notebook, just to see if I see the behavior. My version of Notebook is 6.5.2, with Ipython 8.8.0 (and that matters too since it' s Ipython methods that render html). I also happen to be running Python 3.11 in it. No telling which all things may make a difference.

Tom

tomweber-sas commented 1 year ago

Well, the more I play around with this, on both platforms, the more I see some issues. I wasn't able to get any themes added to Notebook, yet. In Lab, when changing to the dark mode, the SAS ODS output is sometimes messed up. If I try to change the SAS HTML Style, then other things happen, and it varies between Notebook and Lab. There's clearly not a clean segregation between the HTML Themes of Jupyter (and the webpage) and the HTML that's rendered for a given cell, that being the HTML that was returned by the method. (SAS's ODS HTML5 output). I'm not much of an HTML expert but clearly there's bleed through between rendering output for a cell and the overall rendering of the web page itself. I'm not sure what, if anything I could do to address this. I'll keep playing around to see if I can see if there's a pattern that maybe I can see or try to do something about. But I'm not sure I can control any of this. Tom

tomweber-sas commented 1 year ago

ok, it gets even more strange, but Lab is certainly better than Notebook as far as how much is being affected. What I've just been trying is changing Jupyter themes and ODS Styles. When both are more compatible (both are dark or both light) then the overall behavior is much better; complimentary styles/themes. When they are opposite, then Notebook is just terrible, while Lab is at least reasonable. For your case, using Notebook, and setting a dark Theme, can you try changing the Style to a dark one as well (I tried Raven) and see if at least is acceptable; you can see and read everything across the notebook? You can set the ODS Style in your sascfg_personal.py file via:

SAS_output_options = {'output' : 'html5',
                      'style'  : 'Raven'}

But you can also change it on the fly (though with the screwy interactions, this doesn't work 100%) by changing the value which is stored in the SASsession object as the attribute HTML_Style. What I found was changing it on the fly only really worked if you cleared any exisingly rendered output from the other style. Yeah, it's really crazy how this is all intertwined on the web pages.

sas.HTML_Style='HTMLBlue' # sas.HTML_Style='Raven'

Hopefully, since I don't know how I could fix any of this (it's different in how it behaves between Notebook and Lab, and even different versions of them), changing the SAS ODS Style to a complimentary choice as you set the Jupyter Theme will at least solve this enough that it's usable and things look ok.

I think any of the styles under HTML or HTML5 would work. The doc with the list of these is here: https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/odsug/n13ivejjjk8flyn1jajj8onc3xnw.htm

Can you try setting a SAS Style that's dark with your Notebook dark Theme and see if it works for you?

Thanks, Tom

Debbby57 commented 1 year ago

Hello Tom.

Thanks for your reply !

I am using the Jupyter Notebook Renderers extension (v1.0.10 I admit I am a few versions behind) for Visual Studio Code.

I tried multiples themes in your url and I don't know why but the only theme which works is my_session.HTML_Style='Seaside'

As I install saspy in different projects, and I want to update it easily, I prefer change the theme on the fly like you propose.

Thank you very much !

tomweber-sas commented 1 year ago

Thanks for letting me know. I've only played around with these in Jupyter; I don't have VS Code, so I haven't tried that to see what it does. I may have to install that and see how it behaves. A collogue suggested a different approach, changing some ODS settings which changed the behavior also; kinda having Jupyter's scheme take over more, but left the whole ODS style being inconsistent or overridden partially. Again, I don't know what that would do in VSCode, not to mention any of this in other UI's like Zeppelin or Databricks (they each render HTML their own way as well) that SASPy supports so far.

So, is using a different ODS Style, with your other Jupyter/VSCode Theme working for you acceptably? Or is there more that needs to be done for your use case?

I'm going to still play around with this and see what I can see, including trying VSCode if I can get that set up and working and reproducing the problem.

Thanks, Tom

tomweber-sas commented 1 year ago

I installed VS Code on my PC. I didn't see where to change Themes, but maybe I don't have any till I install that? Still, it was running in a dark mode, so I tried out the python code (jupyter notebook it seems), and saw the same behavior. With the default HTMLBlue ODS Style, once you render a SAS HTML result, you get the white background and dark text for that result, while the text color of the whole document picks up the dark text from the ODS html.

image

If you highlight everything, you can then read the rest of the text on the page; it's still there: image

If I change to use Raven as the ODS Style, and I run everything again (you have to rerender anything that was still sitting there from the HTMLBlue or nothing will change) then everything works as expected. The background for the SAS ODS is dark and matches the rest of the pages backgrounds, while the text is white and again, matches the rest of the page. image

Trying Seaside, it seems to work, but differently; it still had light background and dark text, but doesn't seem to affect the rest of the page. Not sure why. image

Just wondering if this is the same as what you're seeing or different. This is plain vanilla VSCode; I only installed the Python extension to get to this point, so there could be other interactions I'm not seeing.

Tom

tomweber-sas commented 1 year ago

Hey @Debbby57 were you able to see Raven or any other work as expected? I did when I tried. Had to clear everything before it took affect, but it seemed to work well with the Dark theme. Is it working for you? Anything else I can do about this? I haven't found a better solution than setting a compatible Style, which works in the cases I've tried (Jupyter itself, Jupyter in VSCode).

Thanks, Tom

Debbby57 commented 1 year ago

Hello Tom ! Sorry for the late answer. Your solution is enough for me. I will change my HTML Style to "seaside" theme on my notebooks (raven doesn't work for me).

Thank you very much for your investigations and precious help :)

tomweber-sas commented 1 year ago

Ok, thanks! I'll close this one out, but if I happen upon a better solution, I'll reach out! Thanks! Tom