I am trying to build a responsive interface using p5.js.
It uses user responses to update pyo4 object variables.
QUESTION
Can I use Python inside p5.js?
QUESTION
If I can't use Python can I use PHP inside p5.js and evoke Python within PHP?
I tried this simple example without luck:
var htmlString="<?php echo $htmlString;?>"
-
Possible duplicate of Running Python scripts from using PHP exec()TTT– TTT2018年03月17日 01:33:53 +00:00Commented Mar 17, 2018 at 1:33
-
DyZ, that problem is about python inside php right ?DUK– DUK2018年03月17日 01:39:01 +00:00Commented Mar 17, 2018 at 1:39
1 Answer 1
Please try to understand the difference between what happens on the server and what happens on the client.
PHP and Python happen on the server, before the page is loaded. You can use this to change what HTML is shown depending on the request, but once the page is loaded you're pretty much done.
P5.js happens on the client, after the page is loaded. You can use this to modify what's already on the page, but you can't directly interact with server code.
Can I use Python inside p5.js?
No.
If I can't use Python can I use PHP inside p5.js and evoke Python within PHP?
No.
What you need to do is create requests from your P5.js code, which can trigger an endpoint on your server. This is called AJAX and there are a ton of resources online about it.