Q:

Unable to Knit To PDF the R-notebook containing Python code

I am KNIT TO PDF this R-notebook containing the following Python code:

import matplotlib
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.grid(True)
plt.savefig("test.png")
plt.show()

When I choose Knit To PDF, this error appears:

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.

On the other hand, when choosing to Knit To PDF a R-notebook that contains only R code, everything works fine.
Could you please help me resolve this error?

A:

I have found the answer for my question at https://stackoverflow.com/a/50711837/7357673. I posted it here to close this question and for future visitors.

