Have a warning or prompt before closing the Rmarkdown

Can I have prompt or warning before closing the R markdown using runtime::shiny window "like are you sure?" or something similar.
I have a huge R markdown and accidentally closing it is really a pain because I lose all my work.

what is the rmarkdown window ? If you use RStudio IDE, it should warn you if you try to close an unsaved file. Like any other editor I guess... :thinking:

I am using it through runtime::Shiny and I want to know if we can do anything to do for that shiny window

I think you need to work on you reproductible example so that it is easier to understand your issue.

Right now, it is not obvious to me what you are doing, what is going wrong and what you expect.

Rmarkdown is a text file that you can save. With shiny runtime you can execute some shiny element inside this document. This happens in a shiny session in a browser window but what going on in this window can't be saved in the rmarkdown file.

You could find parametrized rmarkdown or shiny application whith shiny bookmarking useful maybe. It is a guess based a small information I have right now.

Thank you.
Please find below an reproductible example. I am running this in Rstudio using Run document

---
title: "Untitled"
author: "Name"
output: html_document
runtime: shiny
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

I have this document running. How do I show a prompt or warning before closing shiny session?

I don't think this something that you can do by default.
However, all this is web tech at the end so you may be able to achieve something like that using javascript?
https://code-maven.com/prevent-leaving-the-page-using-plain-javascript

You could maybe find some example on stackoverflow.

Not sure and I can't try but this is a hint to follow I guess.

Inside shiny, you can register callback on event or show modal (or shinyalert :package:), but you need to detect the event of closing and cancel it if you don't want to close.

I let you search further. Hope this helps.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.