positron icon indicating copy to clipboard operation
positron copied to clipboard

"highcharter" charts are not displayed in notebook with R interpreter

Open vinaychuri opened this issue 1 year ago • 3 comments

-Positron Version: 2024.07.0 (Universal) build 21 -MacOS Ventura 13.6.7 -R 4.4.1

library(highcharter)
hchart(mtcars, "scatter", hcaes(wt, mpg, z = drat, color = hp)) 

No chart is displayed inline in the notebook and the following message is displayed. Error rendering output item using 'positron.r.htmlwidget' "[object Object]" is not valid JSON

vinaychuri avatar Jul 11 '24 13:07 vinaychuri

The same error when using plotly library

library(plotly)
plot_ly(economics, x = ~date, y = ~pop,type="scatter",mode="markers")

vinaychuri avatar Jul 11 '24 13:07 vinaychuri

Thanks for the report! I can also repro the "[object Object]" is not valid JSON error in Python notebooks with IPyWidgets.

Note that highcharter widgets don't seem to work in console sessions at the moment so that'll need more work.

However, plotly widgets do work in the console, so we should be able fix them for notebooks too.

Proposed solutions

There are three parts to fixing this:

  1. We should return a JSON notebook cell output item for known widget mimetypes here: https://github.com/posit-dev/positron/blob/9979b182c632ad89904c48bb6b440eba6112a6c6/extensions/positron-notebook-controllers/src/notebookController.ts#L321-L325

  2. We're failing to load the required resources in our htmlwidgets notebook renderer inside notebooks (it works in consoles). We currently set the resource roots via the output message before creating our webview here: https://github.com/posit-dev/positron/blob/9979b182c632ad89904c48bb6b440eba6112a6c6/src/vs/workbench/contrib/positronOutputWebview/browser/notebookOutputWebviewServiceImpl.ts#L160-L165

    But that doesn't affect notebooks. We need to figure out a way to get those resource roots for the notebook back layer webview here: https://github.com/posit-dev/positron/blob/9979b182c632ad89904c48bb6b440eba6112a6c6/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts#L1207-L1221

    This will at least fix plotly.

  3. Highcharter doesn't work in the console either. There are a bunch of type errors in the console logs. I'm not sure what the issue is, but looks like something isn't being loaded properly.

seeM avatar Jul 11 '24 14:07 seeM

Some discussion about these highcharter errors in: https://github.com/posit-dev/positron/issues/1742.

seeM avatar Jul 17 '24 13:07 seeM

Verified Fixed

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

Test scenario(s)

library(highcharter) hchart(mtcars, "scatter", hcaes(wt, mpg, z = drat, color = hp))

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

testlabauto avatar Jul 29 '24 14:07 testlabauto

Is this released or still under testing? I tried the same on Positron Version: 2024.07.0 (Universal) build 125 and still no output in Notebook

vinaychuri avatar Aug 02 '24 04:08 vinaychuri

I use the default Dark theme in Positron Version: 2024.07.0 (Universal) build 125 and in R Notebook execute the following code. There is no output but the background of the entire notebook changes!

https://github.com/user-attachments/assets/364b1da8-dc1c-4bfa-b588-a7fae40e9129

library(highcharter)
hchart(mtcars, "scatter", hcaes(wt, mpg, z = drat, color = hp))

vinaychuri avatar Aug 02 '24 04:08 vinaychuri

Hi @vinaychuri,

Thanks for pointing this out! I am able to reproduce what you are seeing.

I verified this with the 107 release but it no longer appears to work. I will reopen.

testlabauto avatar Aug 02 '24 14:08 testlabauto

@seeM In light mode I am seeing this for the cell output (build 125):

Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 

testlabauto avatar Aug 02 '24 14:08 testlabauto

I don't believe any R HTML Widgets are currently supported in ipynb notebooks. I've created https://github.com/posit-dev/positron/issues/4219 to track that. They should work via the console though.

seeM avatar Aug 02 '24 14:08 seeM