How to read a reactive expression from reactivefilereader ?

Hi,

I try to develop a shiny interface which display a graph updated each time the file is change.

For this, I read the file with reactivefilereader.

Then, I read the result of this with a read_csv to skip some lines to be able to display the graph correctly.

That was working with the 1.4 version of the readr package, this is not working anymore with version 2.0.X.

How can I read the reactive expression as a csv file ?

Thanx for your help.

Regards

Do you get any particular error ? its hard to diagnose without ...

Here is a reprex for how to do reactive file read. note the version 2 lazy feature would cause the file to lock on read and not be rewritable so I pass lazy=FALSE.

library(shiny)

tf <-tempfile(fileext = ".csv")

ir_func <- function() write.csv(iris,tf)
mtcars_func <- function() write.csv(mtcars,tf)

ir_func()

ui <- fluidPage(
  shiny::actionButton(inputId = "changer",
                      label = "change"),
  tableOutput("data")
  
)

server <- function(input, output, session) {
  observeEvent(input$changer,
               {
                 if(input$changer %% 2){
                   mtcars_func()
                } else {
                   ir_func()}
               })
    
  
  fileData <- reactiveFileReader(1000, session, tf, readr::read_csv,lazy=FALSE)
    
    
    output$data <- renderTable({
      fileData()
    })
  }
  

shinyApp(ui, server)

Thank you for your quick answer.
I have this error message :

"Warning: Error in : '"TOA5","Meteo_GreEnER_CR6","CR6","8957","CR6.Std.10.01","CPU:METEO_GREEN-ER_v2.4.CR6","5234","_01_Min"' does not exist in current working directory"

I read the file like this :

chemin_min_rea <- reactiveFileReader(1000, NULL,chemin_min, readLines)

and then, I try to make a dataframe to be able to draw a graph :

read_csv(chemin_min_rea, col_types = cols(.default = "c"), skip = 1 )

That was working with the version 1.4.0 of the readr package

"TOA5","Meteo_GreEnER_CR6","CR6","8957","CR6.Std.10.01","CPU:METEO_GREEN-ER_v2.4.CR6","5234","_01_Min" is the first line of the file that is seems to be read as a file by read_csv.

Seems you are using read_csv as though with literal data rather than a file and its tripping you up.

Literal data is most useful for examples and tests. It must contain at least one new line to be recognised as data (instead of a path) or be a vector of greater than length 1.

using readLines just seems an extra unecessary step ...
perhaps try

chemin_min_rea <- reactiveFileReader(1000, 
                                    NULL,
                                    chemin_min, 
                                    read_csv, 
                                    col_types = cols(.default = "c"), 
                                    skip = 1 )

That works, thanks a lot !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.