I'm working on a rather complex app but will provide the most succinct snippets of code to exemplify the issue I'm having. In short I have a function which returns the path to a generated .gif file. I would like to render that newly created image with renderImage.
#Here is the eventReactive that fires a long running process which produces the gif file
animation <- eventReactive(input$animate, {
file <- file()
param <- input$param
lyr <- input$lyr
step <- time_in_secs()
a %<-% animation_handler(file, param, lyr, lisgrid, step)
f <- futureOf(a, default="./src/placeholder-image.png")
if(resolved(f)) {
print("Future resolved!")
return(a)
}
})
renderText({animation()})
renderImage({animation()})
What is so puzzling to me is that the renderText part works just fine and shows me the path to the created .gif. The renderImage line however gives me this error:
Warning: Error in : $ operator is invalid for atomic vectors
101: %||%
100: transform
99: func
97: f
96: Reduce
87: do
86: hybrid_chain
85: renderFunc
84: output$outaac7603e20b14e63
3: <Anonymous>
1: rmarkdown::run
Removing the renderImage line I do not get any errors, although I also obviously don't get the image I'm looking for.
When I try to run my .Rmd document I get an error :
Output created: /tmp/RtmpIJCtdZ/file443d7655998c.html
Warning: Error in value[[3L]]: Couldn't normalize path in addResourcePath, with arguments: prefix = 'mathjax-local'; directoryPath = '/usr/lib/rstudio-server/resources/mathjax-26'
122: stop
121: value[[3L]]
120: tryCatchOne
119: tryCatchList
118: tryCatch
117: shiny::addResourcePath
116: shinyHTML_with_deps
115:
99: doc
98: shiny::renderUI
97: func
84: origRenderFunc
83: output$reactivedoc
3:
1: rmarkdown::run
I have tried to update all packages and run , still it did not work.
Using the environment it was created in using renv() was the solution. Looks like the issue was with updated packages.
I am trying to build a Shiny app that will accept a user-uploaded file as well as some other user-input information (textInput inputs), then send me an email using the textInput objects to fill out the subject, body, etc. while taking the file and attaching it to the email with a specific name, using the mailR package. I've posted the code I'm using below (with email addresses, usernames, and passwords changed).
Code
# load packages
library(shiny)
library(rJava)
library(mailR)
library(timeDate)
##############
##### ui -----
##############
ui = fluidPage(
fluidRow(
wellPanel(title = "Submit Data to the Database",
textInput("name", label = "Name:", placeholder = "Name"),
textInput("email","Email Address:"),
textInput("inst","Institution:"),
textInput("notes","Notes:", placeholder = ""),
fileInput("userdata", label = "Choose CSV File",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")),
actionButton("submitdata",label = "Submit Data")
)
))
##################
##### server -----
##################
server <- function(input, output) {
observeEvent(input$submitdata, {
isolate({
send.mail(from = "myemail#gmail.com",
to = "myotheremail#gmail.com",
subject = paste("New data submitted to WoodDAM from", input$name, sep = " "),
body = paste(input$name, "from institution:", input$inst, "with email:", input$email,
"has submitted data to the wood jam dynamics database.",
"This data is attached to this email",
input$name, "sent the following note accompanying this data:", input$note, collapse = ","),
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "myusername", passwd = "mypassword", ssl = TRUE),
authenticate = TRUE,
send = TRUE,
attach.files = input$userdata,
file.names = paste(timeDate(Sys.time(), FinCenter = "America/Denver"), input$name, "WooDDAM_user_data", sep = "_", collapse = ","), # optional parameter
debug = T)
})
})
}
shinyApp(ui = ui, server = server)
When I run this app in an external viewer (chrome browser), I can input text and get an email to send just fine, but when I upload a test .csv file and click the submit button, it returns the error shown below.
Error
Listening on http://127.0.0.1:3587
Warning: Error in .createEmailAttachments: If not NULL, length of argument 'file.names' must equal length of argument 'file.paths'
Stack trace (innermost first):
77: .createEmailAttachments
76: send.mail
69: isolate
68: observeEventHandler [#3]
4: <Anonymous>
3: do.call
2: print.shiny.appobj
1: <Promise>
When I remove the file.names argument by commenting it out, thinking that will fix things, I get the following error:
2nd Error
Warning: Error in file.exists: invalid 'file' argument
Stack trace (innermost first):
78: file.exists
77: .createEmailAttachments
76: send.mail
69: isolate
68: observeEventHandler [#3]
4: <Anonymous>
3: do.call
2: print.shiny.appobj
1: <Promise>
Does anyone have any suggestions as to how to get this app to send the uploaded csv file without throwing an error? I suspect I'm doing something wrong when I try to feed input$userdata to the attach.files argument of send.mail, but I'm not sure how else to make that input be the email attachment. Although the file names issue is annoying, I could live with not being able to change the file name, as long as the uploaded file gets attached to the email.
Thanks for any help you can provide!
The reason why it doesn't work is that you're providing the object input$userdata to the send.mail function instead of the filepath.
If you print out the contents of input$userdata you can see that it contains the following attributes:
name
size
type
datapath
You should pass the datapath like this: attach.files = input$userdata$datapath.
With this the syntax is corrected, however you may still need to enable less secure apps on your google account if you're keen on using gmail.
I have the R package, one of its function - produce report.
In the inst/markdown I have a template rep.rmd
In the package function ProduceReport() I have this code:
render.file <-"rep.Rmd"
render.file <- system.file(TEMPLATES.PATH, render.file, package=getPackageName())
render.dir <- dirname(render.file)
pdf.file <- "example.pdf"
rmarkdown::render(render.file , quiet = FALSE, output_format = "pdf_document",
output_file = pdf.file)
It works.
But If I change last line to:
rmarkdown::render(render.file , quiet = FALSE, output_format = "pdf_document",
output_file = "d:/help/me/please/example.pdf")
It does not work (all paths are exist). I have the error
"! Undefined control sequence. \grffile#filename ->d:\help
\me\please\example _files/figure-... l.148 ...example_files/figure-latex/unnamed-chunk-2-1}"
pandoc.exe: Error producing PDF Show Traceback Rerun with Debug
Error: pandoc document conversion failed with error 43 "
When I use this variant on linux server it also works
P.S.
I would like to emphasize, that the problem is probably not in the paths (I use standard procedure file.path() to avoid system problems, path in example only for demonstration).
Maybe it's not a very good workaround, but it works on WIN
lol <- rmarkdown::render(render.file , quiet = TRUE,
output_format = "pdf_document")
file.rename(lol, pdf.file)
You can try to use output_dir parameter of rmarkdown::render() function.
I have never seen this error before running a Shiny app and can't find anything about it after Googling. I've tried re-installing the shiny package and restarting R but nothing resolves it. Any insight?
Error after running runApp() from the local directory:
Listening on http://127.0.0.1:6093
Warning: Error in ..stacktraceon..: could not find function "shioptions"
Stack trace (innermost first):
1: runApp
Error in ..stacktraceon..({ : could not find function "shioptions"
Traceback below:
5: Sys.sleep(0.001)
4: withCallingHandlers(expr, error = function(e) {
if (is.null(attr(e, "stack.trace", exact = TRUE))) {
calls <- sys.calls()
attr(e, "stack.trace") <- calls
stop(e)
}
})
3: captureStackTraces(while (!.globals$stopped) {
serviceApp()
Sys.sleep(0.001)
})
2: ..stacktraceoff..(captureStackTraces(while (!.globals$stopped) {
serviceApp()
Sys.sleep(0.001)
}))
1: runApp()
Check the library("shiny") output from your R Console. I think you do not have the package loaded and/or you had an intentional upgrade.