I'm developping an app built on top of a CLI to call various dependent tools. Some of these commands are relatively long to run (up to several minutes) depending on the size of the data. I use shinycssloaders::showPageSpinner() to display a spinner while a task is running. This works great but it's currently not possible to abort a job after it's been launched.
How could I kill a running process (for example by pressing the esc key)? Is it possible to do it in R only or should I necessarily use JavaScript?
Yes there's the process class and the kill() method but I couldn't make them work with shinycssloaders::showPageSpinner().
Anyway, I realised that when the process is running, the app is technically freezing so I can't listen to a keydown event until the process ends. I already tried running the process in an ExtendedTask class without success. So what I'm trying to do won't work unless I manage to fix my ExtendedTask problem.
I'm not calling the wait() method and it's the same if I use run(). I also thought it would run in a parallel process and won't cause any freeze issue but it's definitely not the case. Unfortunately I can't share the code.
I may have to use $wait() in the end because the app executes a shell command that generates an HTML file that will later be displayed in an iframe on the main page. I need to wait for the process to end before being able to show the output. Will see if I can adapt your example to my use case.
Unrelated but in my previous example, I use tryCatch(). I can't manage to capture errors when using process$new(), despite using stderr = "". How would you adapt your example to be able to capture potential errors?
Instead of invoking $wait() you could check if your process finished via process$poll_io(0)["process"] == "ready" as done here:
Another option would be to scan the filesystem for the resulting html file:
Regarding tryCatch: I haven't tested it but I guess the issue is that you'll receive character vectors but tryCatch is triggered by R error objects. Maybe you can listen on process$read_error_lines() and pass it to stop() for further error handling.