plotly / plotly.R

An interactive graphing library for R
https://plotly-r.com
Other
2.57k stars 627 forks source link

Error ggplotly() api_create() with facet() #1047

Closed filipwastberg closed 7 years ago

filipwastberg commented 7 years ago

When creating a ggplot with facet() or facet_grid and trying to send it to www.plot.ly using api_create(), or the now deprecated post_PLOTLY(), I receive a weird error.

library(reshape2)
library(plotly)

p <- ggplot(tips, aes(x=total_bill, y=tip/total_bill)) + geom_point(shape=1)

# Divide by levels of "sex", in the vertical direction
p <- p + facet_grid(sex ~ .)

p <- ggplotly(p)

api_create(p)
Error: lexical error: invalid char in json text.
                                       <!DOCTYPE html> <html lang=en> 
                     (right here) ------^

Any suggestions? Is this a bug?


> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=Swedish_Sweden.1252  LC_CTYPE=Swedish_Sweden.1252    LC_MONETARY=Swedish_Sweden.1252
[4] LC_NUMERIC=C                    LC_TIME=Swedish_Sweden.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plotly_4.7.0       ggplot2_2.2.1.9000 reshape2_1.4.2    

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.11      xml2_1.1.1        magrittr_1.5      munsell_0.4.3     xtable_1.8-2      viridisLite_0.2.0
 [7] colorspace_1.3-2  R6_2.2.1          rlang_0.1.1       stringr_1.2.0     httr_1.2.1        plyr_1.8.4       
[13] dplyr_0.5.0       tools_3.4.0       grid_3.4.0        data.table_1.10.4 gtable_0.2.0      DBI_0.6-1        
[19] crosstalk_1.0.0   htmltools_0.3.6   lazyeval_0.2.0    assertthat_0.2.0  digest_0.6.12     tibble_1.3.3     
[25] shiny_1.0.3       tidyr_0.6.2       purrr_0.2.2       htmlwidgets_0.8   curl_2.6          mime_0.5         
[31] labeling_0.3      stringi_1.1.5     compiler_3.4.0    scales_0.4.1      jsonlite_1.4      httpuv_1.3.3   
```r
cpsievert commented 7 years ago

Works ok for me. Try using the latest dev version devtools::install_github('ropensci/plotly')

filipwastberg commented 7 years ago

Strange. Must be something with our corporate system then. Still get the error. I will try it on my personal computer as well.


> api_create(p)
Error: lexical error: invalid char in json text.
                                       <!DOCTYPE
R version 3.4.0 (2017-04-21)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=Swedish_Sweden.1252  LC_CTYPE=Swedish_Sweden.1252    LC_MONETARY=Swedish_Sweden.1252
[4] LC_NUMERIC=C                    LC_TIME=Swedish_Sweden.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] plotly_4.7.0.9000  xlsx_0.5.7         xlsxjars_0.6.1     rJava_0.9-8        demoskop_0.3.0    
 [6] RWeka_0.4-34       tm_0.7-1           NLP_0.1-10         scales_0.4.1       zoo_1.8-0         
[11] stringr_1.2.0      dplyr_0.5.0        purrr_0.2.2        readr_1.1.0        tidyr_0.6.2       
[16] tibble_1.3.3       pxweb_0.6.3        ggplot2_2.2.1.9000 reshape2_1.4.2    

loaded via a namespace (and not attached):
 [1] jsonlite_1.5      magrittr_1.5      gtable_0.2.0      RWekajars_3.9.1-3 memoise_1.1.0     data.table_1.10.4
 [7] hms_0.3           xml2_1.1.1        htmltools_0.3.6   forcats_0.2.0     haven_1.0.0       curl_2.6         
[13] broom_0.4.2       lattice_0.20-35   htmlwidgets_0.9   plyr_1.8.4        knitr_1.16        git2r_0.18.0     
[19] mime_0.5          R6_2.2.1          shiny_1.0.3       digest_0.6.12     colorspace_1.3-2  devtools_1.13.1  
[25] stringi_1.1.5     crosstalk_1.0.0   lazyeval_0.2.0    labeling_0.3      RJSONIO_1.3-0     httr_1.2.1       
[31] compiler_3.4.0    withr_1.0.2       xtable_1.8-2      munsell_0.4.3     DBI_0.6-1         psych_1.7.5      
[37] Rcpp_0.12.11      parallel_3.4.0    assertthat_0.2.0  tools_3.4.0       foreign_0.8-67    httpuv_1.3.3     
[43] viridisLite_0.2.0 slam_0.1-40       rlang_0.1.1       mnormt_1.5-5      nlme_3.1-131      grid_3.4.0       
talithafs commented 6 years ago

I'm getting the same error, but with add_surface:

p <- plot_ly(x = x, y = y) %>% add_surface(z = z) %>%
  layout(
    title = "Curva de Juros 3D",
    scene = list(
      xaxis = list(title = "Vencimento"),
      yaxis = list(title = ""),
      zaxis = list(title = "Taxa")
    ))

api_create(p, "juros3d_br")
Error: lexical error: invalid char in json text.
                                       <!DOCTYPE html> <html lang=en> 
                     (right here) ------^

Do you have any idea of what that might be? Is this a bug? I've tried with both CRAN and dev versions.

R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

other attached packages:
[1] plotly_4.7.1.9000 ggplot2_2.2.1    

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.10        xml2_1.1.1         
 [3] bindr_0.1.1         magrittr_1.5       
 [5] munsell_0.4.3       xtable_1.8-2       
 [7] viridisLite_0.3.0   colorspace_1.3-2   
 [9] R6_2.2.1            rlang_0.2.0        
[11] httr_1.3.1          plyr_1.8.4         
[13] dplyr_0.7.4         tools_3.4.4        
[15] grid_3.4.4          data.table_1.10.4-3
[17] gtable_0.2.0        crosstalk_1.0.0    
[19] htmltools_0.3.6     lazyeval_0.2.1     
[21] assertthat_0.2.0    digest_0.6.15      
[23] tibble_1.4.2        bindrcpp_0.2       
[25] shiny_1.0.3         tidyr_0.8.0        
[27] purrr_0.2.4         htmlwidgets_1.0    
[29] curl_2.6            mime_0.5           
[31] glue_1.2.0          compiler_3.4.4     
[33] pillar_1.2.1        scales_0.5.0       
[35] jsonlite_1.5        httpuv_1.3.3       
[37] pkgconfig_2.0.1 
Nonamaker commented 4 years ago

Just started getting this error today for api_create on a script that has been running properly for months. Was there every any resolution as to what actually caused some users to get this error?