Skip to content
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

Improve developer experience for notebook preview #6317

Merged
merged 4 commits into from
Feb 7, 2024
Merged

Conversation

hoxbro
Copy link
Member

@hoxbro hoxbro commented Feb 7, 2024

I have been unable to run the Panel Preview inside my Jupyter environment for the longest time. I would get the following message:

 Screenshot 2024-02-07 15 14 28

I have found two reasons for this:

  1. Editable installs do not copy the jupyter-config to the jupyter folder in the env folder. I'm working with the mentality that if there is a problem, delete the environment and create a new one. Which meant the data-files were never really copied for me.
  2. I run BOKEH_RESOURCES=inline jupyter lab, this does not work the panel preview.

After doing 1, I get an infinity wheel spin with a warning in the terminal
 Screenshot 2024-02-07 15 18 24

2024-02-07 15:17:55,875 ERROR: panel.io.jupyter_server_extension - ['\x1b[0;31m---------------------------------------------------------------------------\x1b[0m', '\x1b[0;31mValueError\x1b[0m                                Traceback (most recent call last)', "Cell \x1b[0;32mIn[1], line 12\x1b[0m\n\x1b[1;32m      9\x1b[0m sys\x1b[38;5;241m.\x1b[39mpath \x1b[38;5;241m=\x1b[39m [os\x1b[38;5;241m.\x1b[39mgetcwd()] \x1b[38;5;241m+\x1b[39m sys\x1b[38;5;241m.\x1b[39mpath[\x1b[38;5;241m1\x1b[39m:]\n\x1b[1;32m     11\x1b[0m \x1b[38;5;28;01mfrom\x1b[39;00m \x1b[38;5;21;01mpanel\x1b[39;00m\x1b[38;5;21;01m.\x1b[39;00m\x1b[38;5;21;01mio\x1b[39;00m\x1b[38;5;21;01m.\x1b[39;00m\x1b[38;5;21;01mjupyter_executor\x1b[39;00m \x1b[38;5;28;01mimport\x1b[39;00m PanelExecutor\n\x1b[0;32m---> 12\x1b[0m executor \x1b[38;5;241m=\x1b[39m \x1b[43mPanelExecutor\x1b[49m\x1b[43m(\x1b[49m\x1b[43mapp\x1b[49m\x1b[43m,\x1b[49m\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5NE05V1VYVVdnTGZ2ZF9hZkJmYVNid2hqX2U1eUhNNDUzZFBfdG1XV25qZi1HaTZMT2sxR0I1Vno4TWFOUlZrZWdnQlFnMUJuT0lIaGtJcEJkajBBczJubUtFQW16N3pGUjJidXFCSU1PcXJET3JRcE44Nkh6RnJfb0paaVBISHpKcEhpUFZmTWJ1YkpzN3VDZDI4ekMwSFRjZHJNQnZmS2ZQeGJMMUtydXJwaTdPYm9lbGg5VENMWjZQX1pIYmlQOTVzUGV1SzM0NHVSWWZpZzJmVkVWdmlfNFVucnBiN1ZoelI2LW1wQTQ3VC1wOFFMcWxpQzlfWGplX1daWEEzSEI0VkNva0NDQVFCTWFtdmFicXBFd1BvT3ZROVRSRjNNMUNZaWt5ZkNLSUJVWFJEM0dRQ0dBNncyRU5ob0RTc1B0ZGxFUXdGZzFBblJLWDQ2QnVtb2V1aVBWalJERVdGcHFDTGFocWhxcTlpckFuNkJNbENHbFFJVzgzSncwSm9rMnluSmZNMkJaUHYyZmNOSzF2cDZyU0lCZlBrQ2F1OFNCNnprM0x4b0JCdGVSLWJabjQ3bGFtUWlWRE04dnZvZ2xkdHRHemFtUlU4NUdtbjBVV3ZuZWFUTHI2ZjU5YkY2bHhvV1Z0S2t5OG5WZlMyOXJJa09RdGxZX3BaUW5qNlppV2tsczhxMUppblAzdXpvcXJLc3pUZXY5bGJJY3hucVduQm9zVHlYRzVibzZqcjh4VHpnZHA4OWdMTlQ5VE9abUEtU1RtdnIzOEIycGR2Q3cifQ\x1b[39;49m\x1b[38;5;124;43m'\x1b[39;49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[38;5;124;43m'\x1b[39;49m\x1b[38;5;124;43m/panel-preview\x1b[39;49m\x1b[38;5;124;43m'\x1b[39;49m\x1b[43m)\x1b[49m\n\x1b[1;32m     13\x1b[0m executor\x1b[38;5;241m.\x1b[39mrender()\n", "File \x1b[0;32m~/projects/holoviz/repos/panel/panel/io/jupyter_executor.py:72\x1b[0m, in \x1b[0;36mPanelExecutor.__init__\x1b[0;34m(self, path, token, root_url)\x1b[0m\n\x1b[1;32m     69\x1b[0m \x1b[38;5;28mself\x1b[39m\x1b[38;5;241m.\x1b[39mwrite_lock \x1b[38;5;241m=\x1b[39m tornado\x1b[38;5;241m.\x1b[39mlocks\x1b[38;5;241m.\x1b[39mLock()\n\x1b[1;32m     70\x1b[0m \x1b[38;5;28mself\x1b[39m\x1b[38;5;241m.\x1b[39m_context \x1b[38;5;241m=\x1b[39m \x1b[38;5;28;01mNone\x1b[39;00m\n\x1b[0;32m---> 72\x1b[0m \x1b[38;5;28mself\x1b[39m\x1b[38;5;241m.\x1b[39mresources \x1b[38;5;241m=\x1b[39m \x1b[43mResources\x1b[49m\x1b[43m(\x1b[49m\n\x1b[1;32m     73\x1b[0m \x1b[43m    \x1b[49m\x1b[43mmode\x1b[49m\x1b[38;5;241;43m=\x1b[39;49m\x1b[43mos\x1b[49m\x1b[38;5;241;43m.\x1b[39;49m\x1b[43menviron\x1b[49m\x1b[38;5;241;43m.\x1b[39;49m\x1b[43mget\x1b[49m\x1b[43m(\x1b[49m\x1b[38;5;124;43m'\x1b[39;49m\x1b[38;5;124;43mBOKEH_RESOURCES\x1b[39;49m\x1b[38;5;124;43m'\x1b[39;49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[38;5;124;43m'\x1b[39;49m\x1b[38;5;124;43mserver\x1b[39;49m\x1b[38;5;124;43m'\x1b[39;49m\x1b[43m)\x1b[49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[43mroot_url\x1b[49m\x1b[38;5;241;43m=\x1b[39;49m\x1b[38;5;28;43mself\x1b[39;49m\x1b[38;5;241;43m.\x1b[39;49m\x1b[43mroot_url\x1b[49m\x1b[43m,\x1b[49m\n\x1b[1;32m     74\x1b[0m \x1b[43m    \x1b[49m\x1b[43mpath_versioner\x1b[49m\x1b[38;5;241;43m=\x1b[39;49m\x1b[43mStaticHandler\x1b[49m\x1b[38;5;241;43m.\x1b[39;49m\x1b[43mappend_version\x1b[49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[43mabsolute\x1b[49m\x1b[38;5;241;43m=\x1b[39;49m\x1b[38;5;28;43;01mTrue\x1b[39;49;00m\n\x1b[1;32m     75\x1b[0m \x1b[43m\x1b[49m\x1b[43m)\x1b[49m\n\x1b[1;32m     76\x1b[0m \x1b[38;5;28mself\x1b[39m\x1b[38;5;241m.\x1b[39m_set_state()\n\x1b[1;32m     77\x1b[0m \x1b[38;5;28;01mtry\x1b[39;00m:\n", 'File \x1b[0;32m~/projects/holoviz/repos/panel/panel/io/resources.py:530\x1b[0m, in \x1b[0;36mResources.__init__\x1b[0;34m(self, absolute, notebook, *args, **kwargs)\x1b[0m\n\x1b[1;32m    528\x1b[0m \x1b[38;5;28mself\x1b[39m\x1b[38;5;241m.\x1b[39mabsolute \x1b[38;5;241m=\x1b[39m absolute\n\x1b[1;32m    529\x1b[0m \x1b[38;5;28mself\x1b[39m\x1b[38;5;241m.\x1b[39mnotebook \x1b[38;5;241m=\x1b[39m notebook\n\x1b[0;32m--> 530\x1b[0m \x1b[38;5;28;43msuper\x1b[39;49m\x1b[43m(\x1b[49m\x1b[43m)\x1b[49m\x1b[38;5;241;43m.\x1b[39;49m\x1b[38;5;21;43m__init__\x1b[39;49m\x1b[43m(\x1b[49m\x1b[38;5;241;43m*\x1b[39;49m\x1b[43margs\x1b[49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[38;5;241;43m*\x1b[39;49m\x1b[38;5;241;43m*\x1b[39;49m\x1b[43mkwargs\x1b[49m\x1b[43m)\x1b[49m\n', 'File \x1b[0;32m~/miniconda3/envs/holoviz/lib/python3.11/site-packages/bokeh/resources.py:364\x1b[0m, in \x1b[0;36mResources.__init__\x1b[0;34m(self, mode, version, root_dir, dev, minified, log_level, root_url, path_versioner, components, base_dir)\x1b[0m\n\x1b[1;32m    361\x1b[0m     \x1b[38;5;28;01mraise\x1b[39;00m \x1b[38;5;167;01mValueError\x1b[39;00m(\x1b[38;5;124m"\x1b[39m\x1b[38;5;124msetting \x1b[39m\x1b[38;5;124m\'\x1b[39m\x1b[38;5;124mversion\x1b[39m\x1b[38;5;124m\'\x1b[39m\x1b[38;5;124m makes sense only when \x1b[39m\x1b[38;5;124m\'\x1b[39m\x1b[38;5;124mmode\x1b[39m\x1b[38;5;124m\'\x1b[39m\x1b[38;5;124m is set to \x1b[39m\x1b[38;5;124m\'\x1b[39m\x1b[38;5;124mcdn\x1b[39m\x1b[38;5;124m\'\x1b[39m\x1b[38;5;124m"\x1b[39m)\n\x1b[1;32m    363\x1b[0m \x1b[38;5;28;01mif\x1b[39;00m root_url \x1b[38;5;129;01mand\x1b[39;00m \x1b[38;5;129;01mnot\x1b[39;00m \x1b[38;5;28mself\x1b[39m\x1b[38;5;241m.\x1b[39mmode\x1b[38;5;241m.\x1b[39mstartswith(\x1b[38;5;124m"\x1b[39m\x1b[38;5;124mserver\x1b[39m\x1b[38;5;124m"\x1b[39m):\n\x1b[0;32m--> 364\x1b[0m     \x1b[38;5;28;01mraise\x1b[39;00m \x1b[38;5;167;01mValueError\x1b[39;00m(\x1b[38;5;124m"\x1b[39m\x1b[38;5;124msetting \x1b[39m\x1b[38;5;124m\'\x1b[39m\x1b[38;5;124mroot_url\x1b[39m\x1b[38;5;124m\'\x1b[39m\x1b[38;5;124m makes sense only when \x1b[39m\x1b[38;5;124m\'\x1b[39m\x1b[38;5;124mmode\x1b[39m\x1b[38;5;124m\'\x1b[39m\x1b[38;5;124m is set to \x1b[39m\x1b[38;5;124m\'\x1b[39m\x1b[38;5;124mserver\x1b[39m\x1b[38;5;124m\'\x1b[39m\x1b[38;5;124m"\x1b[39m)\n\x1b[1;32m    366\x1b[0m \x1b[38;5;28mself\x1b[39m\x1b[38;5;241m.\x1b[39mroot_dir \x1b[38;5;241m=\x1b[39m settings\x1b[38;5;241m.\x1b[39mrootdir(root_dir)\n\x1b[1;32m    367\x1b[0m \x1b[38;5;28;01mdel\x1b[39;00m root_dir\n', "\x1b[0;31mValueError\x1b[0m: setting 'root_url' makes sense only when 'mode' is set to 'server'"]

Therefore, I updated EXECUTION_TEMPLATE to set BOKEH_RESOURCES to 'server' if they are 'inline'. And with that, I can finally get the experience of Panel preview, like a normal user.
 Screenshot 2024-02-07 15 19 33

setup.py Show resolved Hide resolved
Copy link

codecov bot commented Feb 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5578f98) 82.75% compared to head (d50ba76) 82.57%.
Report is 1077 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6317      +/-   ##
==========================================
- Coverage   82.75%   82.57%   -0.18%     
==========================================
  Files         239      305      +66     
  Lines       34507    45445   +10938     
==========================================
+ Hits        28555    37527    +8972     
- Misses       5952     7918    +1966     
Flag Coverage Δ
ui-tests 38.35% <ø> (+0.23%) ⬆️
unitexamples-tests 71.67% <ø> (-2.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@philippjfr philippjfr merged commit aae654c into main Feb 7, 2024
13 of 15 checks passed
@philippjfr philippjfr deleted the notebook_preview branch February 7, 2024 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants