plotly / plotly/plotly.R

save_image Error

Open
#2,494 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

Dear All,
I am using R 4.6, and i run the following code

 reticulate::use_python(reticulate::install_python())
 reticulate::py_require(c("kaleido", "plotly"))
  p <- plot_ly(x = 1:10)
  tmp <- tempfile(fileext = ".png")
  save_image(p, tmp)

I get the following error

Error in py_run_string_impl(code, local, convert) : 
    File "<string>", line 1
    import json; fig = json.load(open('C:\Users\310677\AppData\Local\Temp\Rtmpq0iC7T\filec73864b9a23.json'))
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Run `reticulate::py_last_error()` for details.

then i run r reticulate::py_last_error()

reticulate::py_last_error() ── Python Exception Message ─────────────────────────────────────────────────────────────────────────────── File "", line 1 import json; fig = json.load(open('C:\Users\310677\AppData\Local\Temp\Rtmpq0iC7T\filec73864b9a23.json')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape ── R Traceback ──────────────────────────────────────────────────────────────────────────────────────────── ▆ 1. └─plotly::save_image(p, tmp) 2. └─kaleido()$transform(...) 3. └─reticulate::py_run_string(load_json) 4. └─reticulate:::py_run_string_impl(code, local, convert) See `reticulate::py_last_error()$r_trace$full_call` for more details. --   > | > >

Please advise.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at plotly::save_image(p, tmp), following kaleido()$transform into reticulate::py_run_string(load_json); reproduce the failure on Windows with the shown temporary path. Done means the JSON loads successfully and save_image writes the PNG without the Python unicodeescape error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.