0

To elaborate on the title,

I am using rstudio making an rmarkdown file that contains both r and python code. My configuration is below:

Running under: Windows 10 x64 (build 18363)

Matrix products: default

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

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

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6         rstudioapi_0.11      knitr_1.28           magrittr_1.5         rappdirs_0.3.1       tidyselect_1.0.0    
 [7] munsell_0.5.0        lattice_0.20-38      colorspace_1.4-1     R6_2.4.1             rlang_0.4.5          dplyr_0.8.5         
[13] tools_3.6.3          grid_3.6.3           gtable_0.3.0         xfun_0.12            htmltools_0.4.0      yaml_2.2.1          
[19] assertthat_0.2.1     digest_0.6.25        tibble_2.1.3         lifecycle_0.2.0      crayon_1.3.4         Matrix_1.2-18       
[25] purrr_0.3.3          ggplot2_3.3.0        rsconnect_0.8.16     glue_1.3.2           evaluate_0.14        rmarkdown_2.1       
[31] compiler_3.6.3       pillar_1.4.3         scales_1.1.0         jsonlite_1.6.1       reticulate_1.15-9000 pkgconfig_2.0.3 

The python chunk I try running is:

import scipy as sp
import numpy as np
import pandas as pd


df = pd.read_csv("D:/03 PhD Edinburgh related/OneDrive/OneDrive - University of Edinburgh/00 PhD/000 PhD Data/01 Project I Chr Hansen/20200421_analysis_pp16013/20200420_pp16013_analysis.csv")

plt.scatter(df['OD'].values, df['osmolarity.mOSM'].values,
            c=df['hydrophobicity'].values,cmap='magma')
plt.xlabel('OD')
plt.ylabel('osmolarity')
plt.title('osmolarity as function of OD and Hydrophobicity')

cbar = plt.colorbar()
cbar.set_label('Hydrophobicity', rotation=270)

plt.show()

I can run the python chunk fine in rStudio and display the graph as expect.

When I try using knitter to make the document it gets to the python chunk and gives the error:

"This application failed to start because it could not find or load 
the Qt platform plugin "windows" in "", 
reinstalling the application may fix this problem."

This is specifically related to the part using matplotlib. I can create and display the Pandas data frame.

I have tried installing the latest version of reticulate of github.

Thank you for any help in advance.

  • Did you try to google this error message? I found [this](https://forum.qt.io/topic/90293/could-not-find-or-load-the-qt-platform-plugin-windows-in) – J_F Apr 22 '20 at 12:24
  • Yes, google revealed that it is most likely related to the reticulate package. I followed instructions to update to the most recent version by directly installing the package from github. – Mark Zurbrügg Apr 22 '20 at 12:40
  • But the link I provided talks about the PATH to modify when this error occurs. – J_F Apr 22 '20 at 17:47

2 Answers2

1

In my rmarkdown file, it works fine after setting the plugin path of the conda environment being used. You can add the below r code chunk before using matplotlib for python code chunk.

library(reticulate)
py_run_string("import os as os")
py_run_string("os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:/Users/[UserID]/Anaconda3/envs/[EnvironmentName]/Library/plugins/platforms'")
Dusan Ku
  • 11
  • 1
  • Hi thanks I feel like this is going in the right direction. I tried using my installation of python: C:/Users/mzurb/AppData/Local/Programs/Python/Python38-32/python.exe This did not work can you tell me what this platforms folder is as I do not have anaconda3? – Mark Zurbrügg Apr 24 '20 at 13:01
  • In my platforms folder, I can find "qwindows.dll" file. Maybe, you can try locating the file around your installation folder, and point to the folder containing the file if you could find one? – Dusan Ku Apr 24 '20 at 18:57
1

I have managed to find the issue in another stack overflow answer this is a duplicate.

For answer please look here.

https://stackoverflow.com/a/50711837/11076186

I basically just save my python plot and then load the saved python plot in r.