I'm doing digital signal processing work in R using R Studio and think it would be a neat idea to expand this into an Android app. I know people have used Kivy to develop Android Apps in Python and I know it's possible to wrap R code in Python, so is this feasible? I read that it's possible to run R code on Android, just not sure if adding it to my project is a possibility. I also don't need to have the entire app to be written in R. Are there any examples/documentation related to this?
Asked
Active
Viewed 2,521 times
4
-
Possible duplicate: https://stackoverflow.com/q/36968411/3358272 – r2evans Nov 06 '18 at 01:31
-
1Just because I've never *heard* of a deployed app running R does not mean there are none ... but I haven't. Give it a try! I might buy it. – r2evans Nov 06 '18 at 01:32
-
I'll give it a try and post a response! – Amanda Doan Nov 06 '18 at 16:03
1 Answers
3
Turns out you can! I've built a more complex app using Kivy and the rpy2 package, but I'll demonstrate a simple example here.
You can define your R code like so: r_code.py
from rpy2.robjects.packages import SignatureTranslatedAnonymousPackage
r_code = """
add <- function(x, y) {
return(x + y)
}
"""
r_lib = SignatureTranslatedAnonymousPackage(r_code, "r_lib")
Your Kivy App will look something like this: main.py
from kivy.app import App
from r_code import r_lib
class MainApp(App):
def build(self):
window = BoxLayout(orientation='vertical')
label = Label(text=str(r_lib.add(3, 4)[0]))
b.add_widget(label)
return b
if __name__ == "__main__":
MainApp().run()
And if you want to package this into an Android App, you can follow the directions from the official doc. If you run into an error with rpy2, you might have to install the correct version for your system from here.
Happy coding!

Amanda Doan
- 81
- 1
- 8