pythonrpython-3.xshinyshiny-server

Python is not able to find libraries while accessing from shiny script


I have a python script which is working fine while I'm running it from terminal. The same script I'm trying to invoke from shiny application with the arguments, but the shiny-server log says File "/home/linuxadmin/Desktop/ADLS_test2.py", line 9, in <module> from azure.identity import DefaultAzureCredential ModuleNotFoundError: No module named 'azure.identity' But pip list is displaying azure-common 1.1.28 azure-core 1.29.5 azure-identity 1.15.0 azure-keyvault-secrets 4.7.0 azure-storage-blob 12.19.0

I could understand that python is not able to recognize the libraries while the script is invoking from shiny server app. Below is the sample script from shiny-server app I'm trying to invoke python file. How do I set up the python libraries path to look for, in the Python file?

server <- function(input, output, session) {

observeEvent(input$submitid,{
 source <- renderText({ input$caption })
 destination <- renderText({ input$caption2 })
 system('python3 /home/linuxadmin/Desktop/ADLS_test2.py source destination')
 output$info <- paste0('Source : ', source, ' | Destination : ', destination)
})

}

Solution

  • Finally, thanks to this question Access the output of python script in R executed through system command which gave me clue about how to mention the python path in system command. First I had to get the python installed path from the machine and instead of just system('python3 /home/linuxadmin/Desktop/ADLS_test2.py source destination') , I had to give this way. system('/usr/bin/python3 /home/linuxadmin/Desktop/ADLS_test2.py source destination'). This way the python is able to import the libraries when invoked from shiny app.