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

Bokeh support #4118

Closed
nstrayer opened this issue Jul 22, 2024 · 5 comments
Closed

Bokeh support #4118

nstrayer opened this issue Jul 22, 2024 · 5 comments
Assignees
Labels
area: plots Issues related to Plots category. area: ui Issues related to UI category. theme: app builder

Comments

@nstrayer
Copy link
Contributor

A sub-issue of #1924
Currently, bokeh plots don't work as one would hope.

If running plain bokeh plot code: e.g.

from bokeh.plotting import figure, show
p = figure(title="Simple line example", x_axis_label='x', y_axis_label='y')
p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], legend_label="Temp.", line_width=2)
show(p)

The plot shows up, but in an external browser window:
image

If you try and get clever and use the notebook mode things get even less useful:

from bokeh.io import output_notebook
from bokeh.plotting import figure, show
output_notebook()
p = figure(title="Simple line example", x_axis_label='x', y_axis_label='y')
p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], legend_label="Temp.", line_width=2)
show(p)
image (Note the two empty plot examples that have shown up.)

The error that appears in the javascript/webview developer console is the helpful:

Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing
@nstrayer nstrayer added area: plots Issues related to Plots category. area: ui Issues related to UI category. theme: app builder labels Jul 22, 2024
@nstrayer nstrayer added this to the 2024.09.0 Pre-Release milestone Jul 22, 2024
@seeM
Copy link
Contributor

seeM commented Jul 23, 2024

It's worth checking if this works in VSCode. If so, we may just need to wire something up properly (probably in the notebook output webview service or positron notebook controllers).

@nstrayer
Copy link
Contributor Author

Using vscode the plain bokeh plot output opens in an external browser as well.

Image

@peekxc
Copy link

peekxc commented Jul 30, 2024

(To be clear, calling output_notebook() first does allow one to render a bokeh plot inline via the interactive terminal)

nstrayer added a commit that referenced this issue Jul 30, 2024
…localhost (#4178)

Addresses #4118 

Hooks into the new `'show-html-file'` comm path to display html files
opened with the `webbrowser` python module in the viewer pane.

Previously we overrode the `webbrowser` opening to forward localhost
servers, so this just adds a condition to check for html files and do a
similar thing.

Here's an example of it working on a bokeh plot that previously used to
open in an external browser:
<img width="1115" alt="image"
src="https://github.com/user-attachments/assets/d258ae4e-f8d2-449a-8490-b99bb282aaca">


Rough edges:
- Bokeh widget doesn't seem to care about the size of the viewer pane.


<!-- Thank you for submitting a pull request.
If this is your first pull request you can find information about
contributing here:
  * https://github.com/posit-dev/positron/blob/main/CONTRIBUTING.md

We recommend synchronizing your branch with the latest changes in the
main branch by either pulling or rebasing.
-->

<!--
  Describe briefly what problem this pull request resolves, or what
  new feature it introduces. Include screenshots of any new or altered
  UI. Link to any GitHub issues but avoid "magic" keywords that will 
  automatically close the issue. If there are any details about your 
approach that are unintuitive or you want to draw attention to, please
  describe them here.
-->

### QA Notes

<!--
  Add additional information for QA on how to validate the change,
  paying special attention to the level of risk, adjacent areas that
  could be affected by the change, and any important contextual
  information not present in the linked issues.
-->
@testlabauto
Copy link
Contributor

Verified Fixed

Positron Version(s) : 2024.07.0-125
OS Version          : OSX

Test scenario(s)

Verified fixed using original filing criteria. Will keep an open for dialog related functionality with upcoming tickets.

Link(s) to TestRail test cases run or created:
N/A

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2024
@jonvanausdeln
Copy link
Contributor

This doesn't seem to work on windows. The sample code results in:

{
	"name": "PermissionError",
	"message": "[Errno 13] Permission denied: 'c:\\\\Program Files\\\\Positron\\\\resources\\\\app\\\\extensions\\\\positron-python\\\\python_files\\\\positron\\\\positron_language_server.html'",
	"stack": "---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
Cell In[1], line 4
      2 p = figure(title=\"Simple line example\", x_axis_label='x', y_axis_label='y')
      3 p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], legend_label=\"Temp.\", line_width=2)
----> 4 show(p)

File ~\\.pyenv\\pyenv-win\\versions\\3.12.2\\Lib\\site-packages\\bokeh\\io\\showing.py:147, in show(obj, browser, new, notebook_handle, notebook_url, **kwargs)
    144 state = curstate()
    146 if isinstance(obj, UIElement):
--> 147     return _show_with_state(obj, state, browser, new, notebook_handle=notebook_handle)
    149 def is_application(obj: Any) -> TypeGuard[Application]:
    150     return getattr(obj, '_is_a_bokeh_application_class', False)

File ~\\.pyenv\\pyenv-win\\versions\\3.12.2\\Lib\\site-packages\\bokeh\\io\\showing.py:198, in _show_with_state(obj, state, browser, new, notebook_handle)
    195     shown = True
    197 if state.file or not shown:
--> 198     _show_file_with_state(obj, state, new, controller)
    200 return comms_handle

File ~\\.pyenv\\pyenv-win\\versions\\3.12.2\\Lib\\site-packages\\bokeh\\io\\showing.py:179, in _show_file_with_state(obj, state, new, controller)
    175 def _show_file_with_state(obj: UIElement, state: State, new: BrowserTarget, controller: BrowserLike) -> None:
    176     '''
    177 
    178     '''
--> 179     filename = save(obj, state=state)
    180     controller.open(\"file://\" + filename, new=NEW_PARAM[new])

File ~\\.pyenv\\pyenv-win\\versions\\3.12.2\\Lib\\site-packages\\bokeh\\io\\saving.py:98, in save(obj, filename, resources, title, template, state)
     95 theme = state.document.theme
     97 filename, resources, title = _get_save_args(state, filename, resources, title)
---> 98 _save_helper(obj, filename, resources, title, template, theme)
     99 return abspath(expanduser(filename))

File ~\\.pyenv\\pyenv-win\\versions\\3.12.2\\Lib\\site-packages\\bokeh\\io\\saving.py:166, in _save_helper(obj, filename, resources, title, template, theme)
    163 from ..embed import file_html
    164 html = file_html(obj, resources=resources, title=title, template=template or FILE, theme=theme)
--> 166 with open(filename, mode=\"w\", encoding=\"utf-8\") as f:
    167     f.write(html)

PermissionError: [Errno 13] Permission denied: 'c:\\\\Program Files\\\\Positron\\\\resources\\\\app\\\\extensions\\\\positron-python\\\\python_files\\\\positron\\\\positron_language_server.html'"
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: plots Issues related to Plots category. area: ui Issues related to UI category. theme: app builder
Projects
None yet
Development

No branches or pull requests

5 participants