Does Bubble integrate with R?

I’d like to update a table in Bubble with a calculated field that is calculated with R. Does Bubble integrate with R?

1 Like

If you use a custom block and Blockspring you can type some R. Bubble doesn’t support this natively.

Cool! Got a mini-R function working that adds 2 parameters input bubble-side.

Now for the real-deal. I need R to run a calculation on a table that lives in Bubble. I can write the R function in Blockspring, but instead of passing just a single value parameter from Bubble to Blockspring, I need to pass an entire table.
Ie. Bubble passes table values to Blockspring/R function and Blockspring/R function returns table to Bubble.

Does this seem doable? If it could be done, it would wholly avoid a separate virtual env for running R!

Interested to get your thoughts

What do you mean by a table? If can return a list of data yes, as another Blockspring block, which I believe is what you mean.

By table, I mean that I want to take data that lives in the Bubble database and pass that to a Blockspring/R function. I’m totally open to how this happens so long as it’s not manual :slight_smile:

Sounds like you’re familiar with Blockspring, which is awesome. I didn’t see ‘list’ as a parameter type (https://www.blockspring.com/docs/inputs). Do you think Bubble could accomplish this task with type = spreadsheet or type = file?

Specifically, this is what I’d like to do between Blockspring & Bubble.

library(“blockspring”)
AvoidEC2theFunction <- function(request, response){
Pass data from bubble database to blockspring (can type = ‘file’ or ‘spreadsheet’ can achieve this? )
Dataset = request$params$spreadsheet
R code within blockspring does a fancy calculation like so…
TwoRows = dataset[1:2,]
Blockspring passes the data back to Bubble
response$addOutput(“output to go back into bubble database”, TwoRows)
response$end()
}
blockspringDefine(block)

I’d appreciate any suggestions. The next best alternative for doing this seems kinda ugly.

Thanks in advance!


I also see that Blockspring input is a .json file of the format:
https://www.blockspring.com/docs/r-components

One alternative if the type = file or type = spreadsheet would be to devise a way to get the Bubble database to output .json that would trigger Blockspring to run and return a result. Not sure I understand how this would work, but thought you might if plan A is a no-go.

I’ve not really used custom blocks put its type should be automatically recognized. If not can you make the block open source and make your app public (we’d need an R expert though:))

I have a similar question but want to use Python instead for the calculation. Does this seem possible?

Also, not to mix in too many questions but how would authentication work? For example, if I have several users who have a login to the Bubble-based site, then each can call some logic from elsewhere (my Python program), but that logic as well as results need to be saved (in-process), is there a way to do that? Is there a way to do that again? For example, we take columns A and B from the file and calculate a column C. The user wants to save this state (the “formula” in C) to use again in next login as well as a snapshot of the results (the values in C). Other users should not see the formula or values for this user. Is this security via obscurity or can I pass around some token, oauth-style?

Excited to use Bubble but afraid I may not be able to do the more advanced backend aspects of my app.

Yes, all of this is doable in Bubble. You’ll just need to have the Python scripted hosted elsewhere and have an API for it.

I’d recommend looking at Blockspring. That’d be an easy solution for hosting (and they auto-create an API) so it should work as long as your Python script can run on Blockspring (i.e., it doesn’t require specific packages that aren’t already available).

To do this, you’ll want to send data from Bubble (via the API Connector, I believe it’s called) to an endpoint where your script is accessible (i.e., a URL where it’ll receive the data). The Python script can then reply to Bubble (you’ll need to set-up an API Endpoint to receive the data back, I believe) and you’ll want to store that data in Bubble’s database so it’a available for future use. Additionally, you can secure the API calls with a token so that it remains private in transit. And, you can set-up security in Bubble as well to ensure the data remains private.

Side note - we’ve found the API to be the most confusing part of Bubble. So, definitely look for answers on the forum and post new ones if you’re stuck.

1 Like

Thanks a lot, Sridharan. That sounds feasible for an MVP at least. On the other hand, since I feel I need to code the back end I may end up coding the front end, too, though I would prefer not to do so. I’ll first see if I can do things this way.

I really like the Bubble concept. I wish it could do: 1. be transparent about the code that it generates so more advanced users can then take that and modify it. That may seem in conflict to the business model but I think it would expand the utility to another group of users (people who can code web apps but don’t want to code everything manually) who could modify/write code only when necessary and use the Bubble UI for everything else. As someone who can code, I still strongly believe in not coding except when you are forced to. Then, a GUI can actually get in the way. 2. allow Python usage on the back end, including virtual environments so users can pip install what they need, especially for data science (for example, think about building fake Twitter but not just the front end and simple posts but all of the data science including recommendations on whom to follow and ad matching tech).

Given my current idea for an MVP, I’d essentially be cobbling together code (generated and hand-written) on two PaaS, one for front end, one for a logic tier. With some simple additional functionality in Bubble, it’d be easiest to stay on Bubble past MVP/POC and keep growing and getting more sophisticated on only one platform, saving time, money, headaches.

I understand your take on all of this. I thought the same at one point. A few related thoughts that have shaped my opinion more recently:

  • Large tech products usually use a SOA (service oriented architecture). For example, TripAdvisor does this. This means that they separate portions of their codebase into services. Things like algorithms are put into a separate service and then they’d call that service (via an API) when it’s needed. There are numerous reasons for this, such as: better scaleability, MVC architecture, enabling each service and hosting set-up to be optimized for it’s use case, etc. So, I don’t think this set-up at all limits Bubble’s viability for long-term use.
  • Bubble supports you using your own code via APIs. This is a good solution in many ways since it forces you to create MVC (Model - View - Controller) compliant architectures which is a best practice with software engineering. Doesn’t solve for problems with custom code on the front-end, though, which is a whole different challenge.

All in all, setting up Blockspring separately may take a little bit of work up-front, but it’s a low cost, robust, well architected long-term solution. As I mentioned, this is the more complicated stuff to do with Bubble in my experience simply because there’s not a ton of documentation around it so it may take a while to figure out. That said, once you have it set-up and know how this portion of Bubble works, I wouldn’t anticipate that it’ll create many headaches.

Thanks a lot for the follow-up answer. That makes me more optimistic about trying this method and knowing the architecture makes good sense. I’m not too worried about the headaches. Bubble already simplified all of the usual “chores”. Now I get to just focus on the logic that I want to build. If I can make an MVP and go beyond that in this way, I’ll definitely do so. Really excited to go code without doing much actual coding.