Using readline(prompt = "") in rMarkdown - r

I'm currently attempting to automate some statistical report generation, however to do so I would like to collect a couple of piece of information from the user before beginning, then create a markdown report from it.
When knitting the document however it hangs forever because it has no route to receive the user input from. Does anyone know of one, or would it be a case of using a separate r script to gather the information then using calling the report generation from within that using rmarkdown::render?

You could embed a Shiny app or make use of parameterized reports in the Rmarkdown document. Without further detail (eg some code), it is hard to tell you more.
I hope that this helps, though.

Related

Is there a way to make R code only able to be run and not edited? Essentially read-only?

I am in the midst of writing some scripts to perform data analysis on large excel sheets faster than by hand. However, my company has a strict quality review system where the program used needs to be validated and secure (i.e. no one can edit it, there is proof of what code was run, etc.). So essentially I would like my code to be able to be ran by my coworkers without them being able to edit the script. I was also interested in inserting prompts that they can fill in (e.g. "Which column would you like to analyze?")
Is all of this possible? I have read a few things online about file permissions but I know that these can easily be changed by the user. I also read about obfuscators but am entirely unfamiliar with their use.
One thought I have is to use Rmarkdown as a method of displaying which lines were run for which results. However, I believe that document could be edited as well? This would also leave the issue of the script itself being able to be edited.

R Shiny include pieces of code (i.e. markdown) directly in UI

I try to include pieces of raw SQL code in the UI of my Shiny application, including code highlighting, but I can't find a way to do this directly.
In short about the application: I let users choose some parameters in dropdowns, which creates a dynamic SQL query, and I want to print this query to show users what happens. Illustrative example here:
I was thinking about including a piece of markdown, because it brings automatically the code highlighting of the SQL query, but can't find a direct way to output pieces of Markdown code.
Markdown would be like:
```sql
SELECT a
,b
,c
,d
FROM table1
```
I know it is possible to include a complete markdown document, using includeMarkdown(path). But since the query is dynamic, I want to output the markdown content directly.
After quite some Googling, I could not find a way to directly output (and mark up) some SQL code in my Shiny application. Help would be highly appreciated!
I found a (quite heavy) way of solving this, using the ShinyAce package, which renders a text editor in your Shiny application.
Working example in Shiny can be found here.
For me this means that I can include the aceEditor() object in the UI.R and update the SQL statement (simple piece of text) on the server side. I can then update the AceEditor using updateAceEditor(session, "ace", value = sqlQuery) where sqlQuery holds the plain SQL query.

Is there a way for RPubs to automatically re-run the markdown document every time the page is loaded?

I currently have a markdown document which scrapes data from a website and outputs a table using that data. I published the HTML to RPubs using the knit function on Markdown. I'm wondering if there is a way for the table to be updated automatically on RPubs without having to go into R and knitting and publishing the document every day. The data from the website changes every day, so the table changes every day as well.
Thank you!
No, RPubs just takes the static HTML file.
What you want is reactive markdown (using shiny) which you can also host for free. (Though unless you run your own server behind a firewall or pay it will be public)
Here is the tutorial: http://rmarkdown.rstudio.com/authoring_shiny.html
In your case, since you don't actually want it to be reactive, just rerun, I don't think you are going to have to change much of your code.

Is it possible to use r markdown with r.net

I am working on a form in vb.net that also needs to produce reports (basically a couple of tables and charts). I was going to create the reports directly through vb.net but recently discovered R.net which lets you use R from .Net. Seeing as there is more support for creating reports in RMarkdown, I was thinking of using R.net to pass the data into R and then hav RMarkdown generate the report pdfs.
So, I wanted to see if it was possible to use RMarkdown with r.net, so far to me it seems like you can only run operations from the regular command line.
Thanks for the help,
Write your report template in markdown (or whatever markup language you prefer), then pass a call to knitr::knit to R.

web based report generation that supports R (or just external programs)

I'm getting quite good at generating one off reports using R / Sweave / Knitr to process a template with R code that gets database data and produces a pdf / html / text / md or odf file, and I'm providing them more and more to users.
Ideally I'd love to provide an easy way for users to request a particular template with particular settings, then pick up the results of that report.
Can anyone suggest something like this, web based or whatever that will support an R / sweave workflow ??
Edit: Generating these reports (sweave'ing or knit'ting) can take a while, 3-5 mins, so support for requesting and later pickup is a must. In addtion multi user support would be good (i.e Bob can't see Jane's reports)
If you want a true, interactive, web-based R framework, I'd strongly recommend taking a look at RStudio's new app: Shiny.
If you actually just want static reports of the PDF/HTML variety, I don't know that you need much to get that off the ground. You're basically just looking to take form-based input from a web page, pass that to R, run your reports, and offer the file as a download.
To build a simple HTML form, PHP would be dead-simple and supported by most hosting providers.
Then use something like PHP's system() function to call your RScript code passing the parameters in that call.
In R, use the commandArgs() function to extract the parameters specified to your script, generate the report.
Offer the generated report to the web user.
If you wanted something more comprehensive, you can look at setting up RApache or a similar technology, but I really think with the amount of effort you'd expend setting that up, you (and your users) would probably be better off using Shiny and getting the benefits of interactivity.

Resources