How to set python settings in Shiny

I am trying to call a function defined in Python script from server.R file in Rstudio.
It works fine locally with below settings snippet.

library(shiny)
library(assertr)
library(shinyjs)
library(lubridate)
library(reticulate)
py_install(c('pandas', 'numpy'))

#earlier code to be able to run locally

Sys.setenv(PATH = "C:\Users\shubhi.birla\AppData\Local\Programs\Python\Python36")
use_python("C:\Users\SHUBHI~1.BIR\AppData\Local\Programs\Python\Python36\python.exe")
source_python("try3.py")

But when the same is published to shiny it throws below error.
Error : could not find a Python environment in shiny

I followed the advice of creating .Rprofile file with setenv but still facing the issue of not able to find python
#.Rprofile
Sys.setenv(RETICULATE_PYTHON = "C:\Users\SHUBHI~1.BIR\AppData\Local\Programs\Python\Python36")

Also, tried creating a virtual env, in that case below error came.
Code:
reticulate::virtualenv_create("python35_env", python = "python3")
reticulate::virtualenv_install("python35_env", packages = c("pandas", "numpy"))
reticulate::use_virtualenv("python35_env", required = TRUE)
reticulate::source_python("try3.py")
Error:
Error in py_discover_config(required_module, use_environment) :
2020-02-13T11:20:44.497109+00:00 shinyapps[1804578]: Python specified in RETICULATE_PYTHON (~.virtualenvs\python35_env\bin\python) does not exist

Could you please guide as to how to do python setting for successful execution from shiny.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.