Spotfire Using Document Properties in R - r

I know that in order to use the document properties and tables in R, you usually use the input and output parameter tabs. Is there a way to get these values just using the script, like you can in the ironpython scripts?
Thanks

No you can't
In an R script, you can only use values of document properties by setting them as an input, and you can only edit them by setting them as an output.
You can find more information about R parameters here.

Related

How to color some numbers in Excel cell using python or R

I have this example of Excel file where the data contain some random values. I generated this using RAND() function.
What I want to do is read this excel file using R so that I can color red and bold the number 9 wherever it appears in the cell. Is this possible to do?
I've been searching on Google a while but haven't been able to figure it out any other way other than using VBA. But it's not an option.
Does anybody have an example of how to achieve this?
What I wanted to do is not possible using any of the python packages - xlsxwriter can only do rich text like I wanted but only on new cell but cannot modify, openpyxl can do a lot of things but not rich text. Wasn't sure if it could be done using R or not, but seems like it's not possible to do what I want done. I saw a Google Group discussion here where they showed a potential method to perform what I wanted, but that method didn't work for me. It showed .jnew is not recognized.
So, instead, what I did is created a function to add a color dot (image) to the cell to delineate that the cell contains the value I'm searching for - 9 in this case. The reason I can't use conditional formatting is because there's another conditional formatting that is applied for another logic.
def __add_color_dots__(self, ws=None, excel_filename=None):
from openpyxl.drawing.image import Image
import os
path = os.path.abspath('blue-dot.png')
image = Image(path)
image.anchor = 'C4'
ws.add_image(image)
return ws
Hope this will help someone later and that this method maybe a useful workaround.

Inserting images in R markdown using a path variable

I am new to R and Rmd and trying to generate a report using Rmd. This report has several images inserted along with the text. I am able to insert an image by hardcoding the path of the image. I have no problems with that but I need the path as a variable because it varies with the project. Can anyone help me with the syntax for calling a variable within a path to the image?
![Relatedness check](/data/array_processing/in_progress/Project123/files/data/plots/Project123.ibd.png)
"Project123" changes based on the project. Is there a way I can declare this variable and call it to define the path?
Help please.
Images can use online R code for dynamic paths and/or alt text. (Early adopters of rmarkdown often tried this method as the default method of including R plots in the reports, using png(filepath...); plot(...); dev.off() followed by what I recommend you use.)
This will allow you to do what you need:
![something meaningful](`r filepath`)
as raw markdown (and not inside a traditional code chunk).
If you aren't familiar with inline code blocks, then know that you can put just about anything in an inline code block. This is handy for including dynamic content in a paragraph of text, for example "the variance of the sample is \r var(sample(99))``". (Often it is just a pre-created variable, if numeric it is often rounded or formated to control the display of significant figures.)

Filling PDF forms in R?

I am seeking a way to automate PDF form filling in R. I cannot find a package written to do this. Is there an option out there?
Alternative solutions I can think of:
Using R to overlay a PDF containing text onto an blank PDF template.
Using R to generate an FDF file that can be read by some other software or code in a different language.
All of these things seem doable in Python. However, my organization leans strongly towards R, and in the past has relied upon software devs to write C# to fill out the forms. I'm hoping to use R to skip over this step.
Thanks!
staplr package now supports this with get_fields and set_fields functions. Note that for this to work pdftk
server must be installed and in your path
get_fields returns a list of fields and their types from a pdf that you can modify
set_fields allows you to fill form according to your modifications. See below code for an example
pdfFile = system.file('testForm.pdf',package = 'staplr')
fields = get_fields(pdfFile)
# You'll get a list of fields that the pdf contains
# along with some additional information about the fields.
# You make modifications in any of the fields by
fields$TextField1$value = 'this is text'
# and apply the changes you have made in a new file
set_fields(pdfFile, 'newFile.pdf', fields)
Note: Currently github version of staplr has fixes that are yet to make into CRAN that affect staplr's ability to write in non-english alphabets. For best experience you may want to install it by doing
devtools::install_github('pridiltal/staplr')

Can the output options using RMarkdown be changed on the fly?

I am trying to automate some reports which should have different names and dates. So I was wondering whether it is possible when rendering the document to change these on the fly? Or whether it is just easier to specify them as headers within the document and remove the title/date options?
In other words, can I change the YAML automatically? Maybe output_options does this?
NOTE: I am trying to create Word documents.
You can using inline R code in the YAML header. See this thread here: YAML current date in rmarkdown

Displaying png files from R into spotfire

I want to pass data from Spotfire to R and then display the plot constructed by R.
What is the best way to do this?
I’ve figured out the trick of putting images into Spotfire. It’s not hard if you follow these directions, but it’s done in a way very different from how you guess you would do it in Spotfire, and that’s why it took me awhile to figure out.
Here’s an overview of how to do it. You create a DocumentProperty which is a binary object, you write some Spotfire code that gives a value to that Document Property, and you display that binary object using a Spotfire Property Control of the “Label” type.
The confusing parts are that you DON’T use the Spotfire “Insert Image” tool at all, and that you DON’T use the filename generated inside the R code in Spotfire at all. Once you get used to the idea that the two most obvious ways you think you would approach the problem in Spotfire are entirely useless and wrong, you can make some progress.
I’ll leave out the spiderplot specifics because the code’s pretty long.
Here’s what you do.
1) Create a document Property in Spotfire of type “Binary”, e.g., “imageThatGoesBackToSpotfire”
2) You write some R code that generates an image and writes it to a file:
# get a temporary directory name on the local machine. You wouldn’t need to do this is you were just
# going to run it on your own, but you need to do it if you intend to let anybody else run it on their own machine.
tempfilebase = tempfile()
# take the tempfilebase and prepend it to a filename.
myFilename<-“someFileName.jpg”
myFullFilename <- paste(tempfilebase,myFilename,sep="")
#open a jpeg
jpeg(filename=myFullFileName)
# generate the image, however you normally would in R
plot(input)
# close the file
dev.off
# open a connection to that file.
myConnection<-file(myFullFileName,open=”rb”)
imageThatGoesBackToSpotfire<- data.frame(r=readBin(myConnection, what="raw", n=(file.info(myFullFileName)$size)))
close(myConnection)
3) Run your R script, above. Select some columns that are the “input” to the plot, and make the R script return outputs to the “imageThatGoesBackToSpotfire” DocumentProperties.
4) Create a text area in Spotfire.
5) Insert a Property Control into the text area of type “label”. (Click on the icon that’s circled in the picture below). This opens a dialog,
You need to register a data function with inputs and outputs, and the specific PNG data needs to be returned as a binary label.
Some details: http://spotfire.tibco.com/tips/2014/02/25/dynamically-displaying-images-in-a-text-area/

Resources