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

Credential issue and lexical error for invalid character in json text. #42

Open
RobWiederstein opened this issue Mar 29, 2020 · 6 comments

Comments

@RobWiederstein
Copy link

Can't push plot from R using plot_ly::api_create(). Get the following error:

Error: lexical error: invalid char in json text.
                                       <html><head> <meta http-equiv="
                     (right here) ------^

In addition, warnings() produces this console output:

'/Users/robwiederstein/.plotly/.credentials': No such file or directory

These are appearing in spite of me setting environment variables for username and api key. More odd, is that plotly accepted the plot once--not sure why.

@nicolaskruchten
Copy link
Contributor

nicolaskruchten commented Mar 31, 2020

does running Sys.setenv("plotly_domain"="https://chart-studio.plotly.com") first resolve this issue?

@nicolaskruchten
Copy link
Contributor

Updated comment above with correct domain name!

@RobWiederstein
Copy link
Author

No, I'm still getting the same error. So I did some more work on it today. Plotly REST API, v2 at https://api.plotly.com/v2/?format=api requires a "platform name and an optional version". It lists the following as examples.

Plotly-Client-Platform: Lisp
Plotly-Client-Platform: Python 0.2
Plotly-Client-Platform: Python 0.2.5
Plotly-Client-Platform: Python 3 0.3.2

I remembered that I updated my version of R. The latest release for R was 2/29/20. So I went back to an old version and this wreaked a different kind of havoc on my code. Now, I'm back to the latest release of R. My code for R is now the following where "p" is a plot rendered with the plotly pkg:

Sys.setenv("USERNAME_PLOTLY" = "<username>")
Sys.setenv("API_KEY_PLOTLY" =  "<api_key>")
Sys.setenv("PLOTLY_DOMAIN"="https://chart-studio.plotly.com")
api_create(p)

Still getting the same error . . .

@RobWiederstein
Copy link
Author

Changed authentication to the following code. This was detailed in the plotly package documentation under "sign up" page 61:

# If you already have a username and API key, please create the following # environment variables:
Sys.setenv("plotly_username" = "me")
Sys.setenv("plotly_api_key" = "mykey")
# You can also change the default domain if you have a plotly server. 
Sys.setenv("plotly_domain" = "http://mydomain.com")

However, the original error was still present with a pointer to the <html> code. The message said that there was an "invalid character in json text". The R program code commonly makes assignments with, for example, p <- 10. It was changed to "=". Also, the code relied on the magrittr package which uses "%>%" for piping. Switched it out for "+".

It's working . . . Show the issue as closed!

@nicolaskruchten
Copy link
Contributor

I'm glad it's working for you! I'm confused about what you ended up changing that made it work, though, can you clarify please?

@RobWiederstein
Copy link
Author

I thought the fig <- fig %>% layout was somehow being interpreted as an html tag and throwing an error. I was able to push it once to plotly, but haven't been able to repeat it. Argh!

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

No branches or pull requests

2 participants