Skip to content

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

Description

@RobWiederstein

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.

Activity

  1. nicolaskruchten commented on Mar 31, 2020

    @nicolaskruchten
    Contributor

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

  2. nicolaskruchten commented on Mar 31, 2020

    @nicolaskruchten
    Contributor

    Updated comment above with correct domain name!

  3. RobWiederstein commented on Apr 1, 2020

    @RobWiederstein
    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 . . .

  4. RobWiederstein commented on Apr 1, 2020

    @RobWiederstein
    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!

  5. nicolaskruchten commented on Apr 1, 2020

    @nicolaskruchten
    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?

  6. RobWiederstein commented on Apr 1, 2020

    @RobWiederstein
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions