R shiny save input of text area globally - r

In my shiny application, I would like to have a textarea field that allows the users to give text input. This can be done with:
ui.R:
tags$textarea(id="item",rows=3,cols=40,placeholder="Type your message...")
verbatimTextOutput("news")
server.R:
output$news <- renderText(input$item)
With this code, I can only see the text input within the current session of the app. My goal is, to save user text input permanently in the app (user gives text input, submits and data will be displayed in the app permanently).
Is this possible with shiny? My idea was to store the data in a global way like googlesheets.

One option is to write the text entry to disk as a plain text file, likely each time the user chooses to (e.g., by hitting a "Submit" button). You can use an actionButton and have an observeEvent that includes the code to save to disk.
Note that you will need to have unique file names to avoid overwriting. You could either use time stamps or take a look at the uuid package to generate random names.
If you are more comfortable with databases, you could, alternatively, set up a SQL table and append a line for each user submission (this would be substantially more reliable, allow you to store meta data with it, and avoid the file naming issues above).
Shiny itself is not designed to store data, though the authors have written up some suggested approaches (available here).

Related

Shiny R get access to colleagues without needing to download the data

I have developed a Shiny App that provides some plots which can be filtered and "play" around them. The thing is, I would like to:
Give access to some colleagues. This means that I would like the app to be private, so when someone access the link, a password is needed to enter.
Don't let the user manage the data. I mean, I don't want the user to download the data, so I would like the data be already "there", in a server or something like that. This part should be my responsability, to put the data available for the rest of the colleagues.
I wonder if these things are possible.
For #1 Have a look at shinymanager package, as per this example
For #2 Save the data as a .csv or .rds in the same directory as the app, and load it on visit. You can also utilize shinyjs::hide and shinyjs::show also if you like to make the download buttons invisible

Optimising Shiny Dashboard plot redraw

I have built a shiny dashboard which has a set of data loaded in as a data frame. It uses dplyr to then select columns, mutate new columns if needed, apply a set of filters and then plot using a variety of high-level ggplot2-based packages.
We try to do the data load, select and mutate just the once. The filtering is sat in a reactive variable, accessed by the plot, and is based upon different input values.
As far as I see this is a pretty standard and typical use case.
I'm wondering whether anyone could advise on workflow patterns to make the output more responsive.
There are two scenarios I encounter with this writing pattern which appear to cause significant user interface delay which I'd like to avoid:
Firstly, when the dashboard first loads it tries to plot the charts using NULL data. I've found I can get around this by using if(is.null(my_data_frame)) and returning geom_blank() rather than our plot. Is there a neater / faster way to do this?
Secondly (and more challengingly): to the right of my plot are a (potentially large) set of filter options to allow the user to analyse subsets. If the user clicks several of these options in rapid succession, Shiny will repeatedly recalculate our reactive() value and replot the chart for each click event: where the user actually just needed to set or clear 5 options. Is there a way to prevent this happening - so if the recalculation isn't complete we don't continue with the plot in progress as we've just made the data stale? Or do you think about grouping options with an update button to prevent this?
In response to your second bullet. Check out shiny's debounce/throttle capabilities. These should slow down the reactive response so your user can finish with the UI control before the chart or presentation element recalculates.
For your first question, try using the req function inside your reactive block. If your plot is waiting on the data frame to load, you can put the code for loading the data frame in a named reactive block (it seems like you may have already done this), then pass that to req. This will prevent the plot from attempting to render until it receives a valid value for whatever you passed to req.
For the second, I'd recommend wrapping your plot render in an observeEvent and having an 'Update' button, if you typically expect users to change multiple options between desired plot updates.
Finally, for added performance, I just saw today that Shiny v1.2.0 has either just been released or is about to be, the major feature of which is plot caching. You can find more details HERE.

create an automatic word report using Rmarkdown

I want to create an automatic report in my shiny Application.
I imagine to create a button at the bottom of all pages of my application.
If you click, all graphs and tables are automatically stored in a list of outputs.
At the end of the analyse, you click in a big button, and you generate an automatic word report with all your outputs inside.
I have no idea to do that.
Do you have some examples ?
When I read on the web is a script *.Rmd separated to UI.R and Server.R.
All outputs are inside the *.Rmd .
But I want that the user have the choice to save outputs they wants.
Many thanks for your advices.
Maïna

How to avoid recalculation in shiny R each time a tab is clicked on?

In my shiny application, I have noticed that when I have multiple tabs, each time I click on the tab, the output is recalculated. I wasn't expecting this behavior since no inputs were changed. How can I keep it so that it only recalculates once an actual input is changed?
You can prepare your calculataions prior and save them to name.rda file with save function, and then add a line load("name.rda") at the beggining of the server.r file - the data will be loaded only at the beggining of your application. Can't help much without your code.

How does one do a dynamic table in IBM Notes 8.5.3 or 9.0.1?

I'm writing a Notes Client application. Web compatibility is a secondary concern. The language is LotusScript.
The specification: a form to enter lines from receipts. The lines are all saved as part of the same document so that they can be signed as an atomic unit.
When a line is added, it is to be formatted into a table for presentation. Ultimately, this architecture is like an input/datastore/presentation split.
I've managed to get the data stored and signed, and I think I've managed to get it deserializing properly (the LotusScript debugger makes it difficult to see, but it looks right). The problem now is the UI.
Looking at the Programmable Table, it is always a tabbed table with only one row shown per tab. I need a programmable table which can dynamically have rows added to it for display, without forcing new tabs to be created.
This suggests that I would need to use a Rich Text field to contain a table, but thus far my attempts to get anything to display when I try to update a Rich Text field in edit mode have failed. I am forced to conclude that it is impossible.
I cannot figure out how I'm supposed to do a dynamically-displayed list of tabular data like this. Any advice?
Most people just create a table with one row and N columns, with a multi-valued field in each column, and use code to append values to each of the fields in parallel. You don't get borders between rows this way or the ability to do variable formatting of cells, and you have to be careful to avoid letting data length exceed column widths in order to keep everything aligned properly.
If you truly want a dynamic table for presentation with all the bells and whistles that you can get in terms of cell formatting, then the Midas Rich Text API from Genii Software is a commercial solution that can do the job.
I blogged about this a couple of years ago: http://blog.texasswede.com/dynamic-tables-in-classic-notes/
This is a non-XPages solution, but of course you can also use XPages to achieve the same/similar result. It does not use tabs, as each row is a separate table.
Alternatively, you can build your Rich Text Table in another NotesDocument, which you then save. Then use NotesUIDocument.ImportItem (which is undocumented, but present in the R8.5 mail template) to update your NotesUIDocument.
Don't forget to delete the other NotesDocument when you're done.
Another option is to build the table in HTML in computed text, and re-open the document every time you modify it. I have inherited a system that does that, and I hate it...so be warned :)

Resources