How To... | R How To... | Using Displayr | Using R and JavaScript
How to Transfer Text in Outputs to the GUI in Displayr
Sometimes when using Displayr, you have text in an output, and you want to enter it into a field in the Displayr GUI. This post describes how to do this.
Consider the situation where you want to create a dropdown control showing possible ages, from 0, 1, 2, all the way up to 122 (the current verified record age for a person). Having to type 0; 1; 2; 3; etc. into the Item list field would be pretty painful. Fortunately, there is an easy hack to avoid this pain (and, if you are creating the item list for a control, an even better way is to link the control to the R Output using the Items from R Output field).
- Insert > R Output
- In the example above, the following code will create the text that I want:
paste0(0:122, collapse = "; ")
(if copying this example, replace the prettily-formatted double quotation marks with the normal ones when you type, as otherwise you will get an error) - In the Object Inspector, select Properties > LAYOUT > Wrap text output (this is not strictly necessary, but usually makes step 5 a bit easier)
- Press Export > Embed and Snapshot and View (note that this will re-publish whatever document you are working on, so if the document is not ready, you are better off doing this in another document)
- Using your mouse pointer, select the text (see below), right-click and select Copy
- Press Done
- Go to wherever you want to insert the text, right-click, and select Paste
You should now have the desired text pasted into the GUI.
Check out more of our handy How To guides!