How can I get a user input from Excel in R dynamically? - r

I'm using Excel to call a script in R.
R eventually generates a graph, on the basis of which I want the user to be able to see and give an input.
Is there any way to get an input into R from Excel during runtime?
Thanks

So I found a solution.
I ran a shell script that called a vbs that invoked a different workbook that ran a vba code that called the original workbook I wanted to work with while R checked the contents of the new workbook until they were changed(which is when the input box was filled in the original workbook).

Related

R Markdown script and R

I am calling one R Markdown script from another R script.Below you can see command
rmarkdown::render((file=paste(path1,"/Dashboard.Rmd",sep="")),params=list(args = myarg))
The script is executed without any problem but is not open automatically.
So can anybody help me how to solve this problem and open this script automatically after running of this command ?
First, your syntax probably isn't doing what you intended. Writing
rmarkdown::render((file=paste(path1,"/Dashboard.Rmd",sep="")),params=list(args = myarg))
will create a new variable named file and use it as the first parameter to rmarkdown::render. A more likely way to get what you want is to write it as
outfile <- rmarkdown::render(paste(path1,"/Dashboard.Rmd",sep=""),
params=list(args = myarg))
This removes the assignment from the first argument, and saves the
result (which is the name of the file that was produced).
Now, on to your question: You need to follow that line with
rstudioapi::viewer(outfile)
to view it in RStudio, or
browseURL(outfile)
elsewhere, because rmarkdown::render doesn't automatically call a previewer.

Writing new data to an existing excel file that has an XML map attached, without losing the XML data in R

I am trying to write to an excel file that needs to be uploaded somewhere. The target software creates an excel file which has an XML map attached to it. I recreated the entire file structure in R using code, but any time I try to write to that excel file, i think R actually deletes the old file and creates a new one instead, because the XML map is gone the moment I start writing any data to it. Loading up the workbook also doesn't seem to bring in the xml map, only the workbook data and sheets.
Is there a way to write data to this existing file within R (or python) without losing the XML map? Now i need to generate a file and manually copy paste the data into the other excel file.
I've been trying with xlsx, readxl, xml2 packages.
In the past Ive deal with a similar problem. To my knowledge, almost all the R packages that interact with excel replace the entire file with a new one. Except the openxlsx package. You can replace specific sheets, and range of cells, whitout touching the rest (data, styling , etc..). One last comment is that I dont know much about XLM maps, but maybe you are lucky.
Here is the vignette:
https://cran.r-project.org/web/packages/openxlsx/vignettes/Introduction.html
Hope it helps

Enter a Csv-File through a Pop-up Window in R

I have seen that there is the nice option to enter an input through a pop-up window which has been created in R.
Is it possible to write a code that creates a pop-up window (or maybe any other nice interface) where one can enter a csv file? (or excel file.)
Would it also be possible to then get an output as a csv or excel file?
I'm thankful for any idea since I'm not sure what is possible in which language. If you think things would be easier in python - let me know. I just thought to work with data frames is very easy in R.
I already explored a bit the package svDialogs
There is for example the function dlgInput() which can take as an input some integer and there are also functions such as dlg_form() etc which do similar things. But I don't find a function that would take a csv file or so as an input.
You can use rstudioapi:
rstudioapi::selectFile("Select File") returns the file path of your select file, to open a csv interactively, you can use following code:
read.csv(rstudioapi::selectFile("Select File"))
You can read more at: https://rstudio.github.io/rstudioapi/reference/file-dialogs.html

how to refresh an excel file from within R?

I have some excel file with simple formulas like =SUM(A1:A3).
I need to import the file into R, but before that I need to refresh the formulas. Is there a way to refresh the file from within R? There are good packages for importing the data in a R dataframe (eg. the R xslx package) but I need to refresh my formulas first.
Any suggestions?
Thanks!
You should be able to do this with RDCOMClient:
library(RDCOMClient)
ex = COMCreate("Excel.Application")
book = ex$Workbooks()$Open("my_file.xlsx")
book$Worksheets("Sheet1")$Calculate() # if you have many sheets you could loop through them or use apply functions based on their actual names
book$Save()
book$Close()
Here's another thread on the underlying VBA

How to read the external excel workbooks inside Formulas using R?

I would like to read the formulas inside a workbook using R. I have an excel file called "link.xlsx" with value 1 at cell A1 and another excel file called "myFile.xlsx" with value A1=[link.xlsx]Tabelle1!$A$1. I tried the following:
library('XLConnect')
wb<-loadWorkbook("myFile.xlsx")
getCellFormula(wb,1,1,1)
I get
[1]Tabelle1!$A$1
and not
[link.xlsx]Tabelle1!$A$1.
1) How I can fix the problem?
2)Is there a way to quickly get the list of external reference workbooks (linked excels) using R?
UPDATE: For the moment, I found a solution using the approach explained here:
Extract hyperlink from Excel file in R
but I still wonder if it is possible to solve the problem into a more compact way.

Resources