0

I'm just lost in r shiny and to be perfectly honest I probably bitten off too much for my meager coding skills however I need help. My r shiny code works except for updating the data once I add need information to the excel file that the data is coming from. The code basically takes data I have collected inside a greenhouse and spits out numerous graphs (I should have 110 graphs over 8 different pages). The graphs work until I try to make the data upload and processing more reactive. I know that reactiveFileReader exists however I am not sure how it interacts with me loading my data through one specific sheet of the excel file.

df<-read_excel("Crop Registration 2022.xlsx",sheet="CSV")

If I have to make a new file that is purely just the data that is possible. Secondly I do a lot of "processing" of the data once I upload it. This processing is to prepare it for all of the graphs. Currently this all occurs before the server and ui parts of the code. I have tried putting it in reactive({}) but it isn't working. I get an error that object x not found (x being something like data_beef in the examples I provide below). Examples of the "processing" that I conduct.

df$Date<-as.Date(df$Date)
df<-arrange(df,Date)
df$Number_Leaves<-as.numeric(df$Number_Leaves)
data_beef<-filter(df,Type=="BEEF")
data_beef_numbleaves<-filter(data_beef,Number_Leaves!="NA")
wil4009
  • 11
  • 2
  • Have you seen the example usage of `reactiveFileReader` here: https://www.clarkrichards.org/2019/10/21/a-shiny-app-that-uses-reactive-data/ ? You could define your own function for doing data prep (in the example `new_data`) then the example shows making a plot based on reactive file reads. – Hutch3232 Jun 09 '22 at 20:37
  • So I have seen examples of `reactiveFileReader` before but it is the last option (in the example you provide it is `readRDS`). I presume I put `read_excel` there but it is where I put `sheet="CSV"` from the original line that has me stumped. But I will try out doing the data prep in a new function. – wil4009 Jun 09 '22 at 20:48
  • Good question - that is what the ellipsis (dots) `...` are for. https://stackoverflow.com/questions/17688938/what-does-passing-an-ellipsis-as-an-argument-mean-in-r?noredirect=1&lq=1 When you pass in `sheet="CSV"`, `reactiveFileReader` will use `...` to pass it on to `read_excel`. See the docs: `?reactiveFileReader` "... Any additional arguments to pass to readFunc whenever it is invoked." – Hutch3232 Jun 09 '22 at 20:51
  • Thanks. I will try that once I finish making that new function for data prep (I have to rework over 100 lines of code for it and it is close to the end of the day for me) – wil4009 Jun 09 '22 at 20:59
  • I might suggest starting with a small/toy example to work out the kinks then build up, but you do you. – Hutch3232 Jun 09 '22 at 21:01

0 Answers0