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

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.

Related

Interactive Document (takes input gives output) in Rpubs

Is it possible to publish an RMarkdown file to Rpubs that takes input and gives out put from the Rpubs site? I want to create a simple calculator related to my job that takes a few inputs and gives an output and, if possible, publish to Rpubs for people to view and use.
SHINY: I know this is what shiny is for, creating interactive apps, but I dont know it very well or how to implement an app I create for multiple people to use, or how to imbed the link to the app, and so on. Just trying to see if this is possible in things I already know how to use
RPubs is for HTML documents that don't require R calculations on the backend. In some instances, there can be some degree of interactivity e.g., brushing and linking plots, filtering data and having the filter propagate to a plot. These happen through the crosstalk package. However, it sounds like you need a shiny app that can take inputs and have R do some calculation of those on the back end. You could host your app on shinyapps.io
It's also possible, depending on how complicated the calculations are, that the entire app could be written in native javascript, which wouldn't require a server-side computation, so could be hosted on any website.

How to write code and view results at the same time?

I am trying to create a rmarkdown document for monthly reports. The issue I have is writing code and trying to visualize what the result would look like in the final document. I can generate and view maps in RStudio but this doesn't show me how they are positioned relative to text and other features within the output document (PDF, HTML etc)
Is there software that exists that allows you to write code in one window and view the product in another as code is developed? At the moment I am knitting the code and viewing the results in a trial and error process. It would be nice to see what the results look like in the document without having to rerun my file each time I change a piece of code and open the output document.
Kind regards,
Simon
If you click the green arrow in the top right of your block of code, it will just run that block of code and won't create a full output file. It will also tell you where an error is if any.

Using readline(prompt = "") in rMarkdown

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.

Sending emails through rmarkdown

Is there a way in rmarkdown, where after you create your html document, you can add a button to email a report that is created in the rmarkdown doc after manipulating with tables? Or is this feature only available in Shiny?
And on top of this, is there a way to import new data into an rmarkdown document without using RStudio. So for example, if I created a reproducible rmarkdown document, can I add a button that can add data from a csv or once again is this only available in Shiny?
I am basically trying to figure out a free way to have clients/coworkers take my documents and let them takeover without them knowing how to use R in the future. Shiny doesn't allow me to do this because the free version requires others to have R installed already and copy and paste the code whereas Shiny Pro costs a good bit of money.

Implement whole R script contains functions into shiny

I have a complex R script which contains many new declared functions. These functions are able to check and clear given file under some requirements.
I want to prepare a simple user interface, where people without any knowledge about R will be able to upload source file, choose some options, and download analysed file without looking into a code.
I prepared a simple shiny app which contains my archival R code in the past, however each time when I want to perform some calculations, I had to use reactive() and add () after each variable.
This time, script is too complex to adjust it to reactive() form.
Is there any way to implement whole R script with avoid this?

Resources