Shiny R Session Aborted when pressing actionButton - r

I'm facing a problem I can't resolve even with options(shiny.trace=TRUE)
It is a webapp that uploads a file and then you click that button to scan() the file you uploaded. When you upload the file all works well. But when you forget uploading the file, the actionButton makes Shiny to abort R, because "R encountered a fatal error".
The output of the debugging function is "RCV {"method":"update","data":{"button:shiny.action":1}} before it aborts.
Before the scan function I write a if(input$button > 0 && !is.null(uploadedFile)) but it stills aborts. (This if statement is within an observe({}) statement.
I've searched around the web but there's nobody who has faced this problem, it seems the problem is within the call of the actionButton... that doesn't manage to do "nothing" when is pressed.
Thank you

Solved: Was a "variable naming" problem. And after finding that, I realized the button wasn't needed in the webapp. Thank you all

Related

Is it possible to clear the Shiny cache when reloading an app?

Is it possible to clear the Shiny cache history when reloading an app? Specifically, I have a textInput for adding a title that doesn't clear when the app is restarted. In other words, all of the titles entered into the app on previous runs have been "remembered" and show up in a dropdown list when the app is rerun or restarted again. I have tried using shinyjs::reset, but that clears the current value and not the ones in the "history". I've also tried updateTextInput with an action button set to " ", but also clears only the current value and not the ones in the "history". I have also tried setting ui as a function using:
ui <- function(req) {
fluidPage(...)
}
as well as:
I found that cache of R Shiny server is updated when the date of creation for the file "app.R" is changed.
So, here is the trick I used:
server <- function(input, output, session) {
Trick file date creation update
onStop(function() {
# File name
p <- paste0(getwd(), "/app.R")
# Update file 'date creation'
Sys.setFileTime(p, now())
}) # onStop
} # server
The idea is to update the date of "app.R" creation after each session.
Neither of these solutions worked for me. Finally, I found this post:
I also found this post:
I have been struggling with this problem for quite a while, and thought I had tried everything, including putting a js button on the shiny sidebar to manually refresh (unfortunately that did not work either). There are two things that did work for me:
Make sure all code to read data from files is NOT in a code chunk with a name OTHER THAN global OR
Manually restart the shiny server when new data is uploaded
Obviously the first one is much more manageable, and a solution that I wish I had known weeks ago when I started playing with workarounds.
But I am not sure what is involved in implementing either, so if someone could clarify that, that would be great.
Any help would be much appreciated.

First function blocking a project opening

I've just read this post: .First function in R as I have previously used the first function when instructed for a short online course in which script was shared and run through with attendees. I don't fully understand much in the post or the use of the first function (I'm a relative beginner), but I think it is related to an error message every time I try to open up a project in R studio, and the project won't open and the session won't close. I can still open the project directly from the Rproject file, but would like to get rid of this issue.
The error in the console is :
Error in ll(class = c("matrix")) : could not find function "ll"
Has something been overwritten in Rstudio? Could someone advise as to how to get rid of this?
Many thanks.

Automatically reloading shiny app when error occurs

This is a follow-up for my previous question Automatically reloading shiny app when add changes.
The solution options(shiny.autoreload = TRUE) works perfect when you want to automatically see changes on the browser which you put in the code.
However, the potential problem occurs when you save unfinished/corrupted file. For example, the following ui code lacks a , sign after the titlePanel function:
fluidPage(
titlePanel("Old Faithful Geyser Datass")
sidebarLayout(...
When you save such a file, you will get an error on your browser
ERROR: Error sourcing your_path/ui.R
R console will help detect the problem with the , sign. My impression was that if I improve my code and save the file, it should reload the browser and show my app correctly. Unfortunately, it doesn't do it.
Interesting thing is that an error in the app does not terminate the connection with the browser. To confirm my word, just reload the app manually using reload button in the browser (after improving your code).
Therofore, I examined how this shiny.autoreload option works. As I expected, it checked the time of file modification and then execute reload function. Then reload function send a message via sendMessage to the addMessageHandler:
addMessageHandler('reload', function(message) {
window.location.reload();
});
So it seems that after improving your code the function should be reexecuted, but it's not gonna happen.
To summarise, I think it's not possible to change it without major changes in shiny but maybe I am wrong. Thanks for any suggestion.
PS.You can manipulate example code here to see the problem.

How to write (or access?) log of errors and warnings in R

Can anyone tell me how to keep a simple log of errors and warnings thrown during sourcing of code in R? Specifically I want to write them to an object during sourcing so I can print them into a message after execution in case the user missed it as the lines scrolled by.
Background: I wrote a small data validation program, about 600 lines, that allows the user to select an excel file which will be automatically imported, processed, and exported again. I tried hard to include automatic checks in the code (such as checking for required column names and throwing a pop up box if not present), but am aware that I can't think of every possible error that could occur, especially with other users. What I would like is to have every error/warning/etc. that occurs during sourcing to be written to an object that I could then call later such as in a pop up box. I have been able to figure out every step except for creating the error log.
ErrorLog <- (code for collecting errors/warnings here)
(Program Code - already completed)
ErrorPopUp <- tkmessageBox(title = "ERRORS", message = paste("
Please note the following errors/warnings occurred during file processing:
",
ErrorLog ,
"To proceed and export file please press OK. To exit the program without
saving, please press cancel."), icon = "warning", type = "okcancel")
(code to continue and export or quit)
I appreciate any ideas, and thx for the patience as I saw many posts on advanced topics such as creating your own error messages or sending them to windows, but none for simply writing an object listing them.

Opening a file using AutoIt

I am using an AutoIt script to automate my application. Following is the command which I am running:
FileOpenDialog ("File Upload", "C:\Documents and Settings\abhishek.kumar\Desktop\Quadrillion work", "Images (*.jpg;*.bmp)", "","WESTF12433.jpg","" )
Send("{ENTER}")
The first command works as it opens up the file open dialog with WESTF12433.jpg file as selected. Now I want to click on open button. How can I do it?
Send("{ENTER}") is not working.
Send is not a good method as it requires the window to be focused, which you can't guarantee. From what you have posted, I would say the best method would be this:
ControlClick("File Upload", "", "Button1")
Edit in response to comments:
Your problem: The fileOpenDialog is blocking execution. You need to think of it as though AutoIt Reads a line, Runs it, then reads the next.
In this case: AutoIt Reads line 1. It creates a FileOpenDialog and WAITS for you to close it. Once it as been closed it reads the next line, and runs that.
Try the following: Create two au3 files, and put the first line in 1.au3 and the second in 2.au3. Run them in that order and see what happens. Send will struggle as the dialog doesn't have focus, but the ControlClick versions should work.
You're not using FileOpenDialog() properly. Its purpose is to interact with the user. If you don't need that, there's no need for it in the first place.
All it does is return the name(s) of the selected files, which you defined already. Can't you just assign the file path to the variable from the start? As per Documentation - Function Reference - FileOpenDialog() :
Success: Returns the full path of the file(s) chosen. Results for
multiple selections are "Directory|file1|file2|..."
This will never work, because AutoIt is not multi-threaded.
Once you open the dialog, it pauses script execution until the user clicks ok, so a Send() function on the next line won't do anything until after.
What you can do is make another script, compile it, and run it just before you open the dialog.
Run("clickOpen.exe")
FileOpenDialog ("File Upload", "C:\Documents and Settings\abhishek.kumar\Desktop\Quadrillion work", "Images (*.jpg;*.bmp)", "","WESTF12433.jpg","" )
This is what would get executed:
WinWaitActive("File Upload")
Send("{ENTER}")
Simple as that! Hope it helps.

Resources