I think the issue is that output which doesn't come from executing a cell
is not displayed (in the case of Javascript, that means not run). You might
be able to make this more easily as an nbextension (a Javascript extension
for the Jupyter notebook interface). I don't know if the current username
is directly accessible from Javascript in Jupyterhub.

You might also want to open an issue on Jupyterhub for an officially
supported way to do the same thing.

On 22 October 2017 at 17:15, Scott Calabrese Barton <
[email protected]> wrote:

> As a supervisor I log into a lot of different JupyterHub accounts, and I'd
> like to be able to see the username of the current login. I wrote a short
> iPython extension
> <http://ipython.readthedocs.io/en/stable/config/extensions/index.html>
> below, which adds the username to the kernel_logo_widget element. It
> works with the %load_ext magic, but I'm not sure how to make it work when
> automatically loaded.
>
> I've tried adding the following to ipython_kernel_config.py:
>
> c.IPKernelApp.extensions = [ 'NameInHeader' ]
>
>
> with the idea that the extension would load with the kernel. This loads
> the extension, but maybe too soon because the header is not changed.  Is
> there a better way to accomplish what I'm trying to do?
>
> # NameInHeader.py
>
> def load_ipython_extension(ipython):
>
>     import re, os
>     from IPython.display import display, Javascript
>
>     uname= os.getenv('USER')
>
>     s='''var s = document.getElementById('kernel_logo_widget').innerHTML;
>          var news= '<span style=\\'color:#919191\\'>_user_ </span>' + s;
>          document.getElementById('kernel_logo_widget').innerHTML=news;
>     '''
>
>     func=re.compile('_user_')
>     s=func.sub(uname, s)
>
>     display(Javascript(s))
>
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/jupyter/0b075d02-3afb-44bd-9003-b3ad34a4975f%40googlegroups.com
> <https://groups.google.com/d/msgid/jupyter/0b075d02-3afb-44bd-9003-b3ad34a4975f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/CAOvn4qi1GURQVRQnN2_TWMyBaWxh7Z_yPY-uRbJV7jb7ovWrBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to