2

I want to run a Python script in RShiny. I'm doing this by source() function but it is giving me error. I'm very new to R. Do anyone know how can I run task1 in Server.R? My OS is Windows.

server.R:

library(shiny) #library
library(shinydashboard) #library
library(devtools)
shinyServer(function(input, output) {
  observeEvent(input$actionID,{
    source("task1.py")
  })
})

task1.py:

from PIL import Image
print("Mayday! Mayday!")

Error that I'm getting is:

Warning: Error in source: task1.py:6:6: unexpected input
5: 
6: from PIL
        ^
  73: source

1 Answer 1

2

That won't work because source() implies that you want the file to be interpreted by R, not by Python.

You can use system() for any command you want to send to the OS, including running Python against a .py.

Example:

system("C:\\Python27\\python.exe my_script.py")

You can specify if R should wait and if any output should be captured, etc.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm getting this error: Warning: running command 'C:\Program Files (x86)\Python27\python.exe tss.py' had status 127
@KnowledgeSeeker That's a different problem, but it sounds like this: stackoverflow.com/questions/18649549/… If you need more help please open a new question for it and link me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.