Using reactiveFileReader function in Shiny

旧城冷巷雨未停 提交于 2020-02-27 07:46:22

问题


I would like your help to access the result elements that the reactiveFileReader function offers me, in which case the result is fileData ()

The server code is this:

    server <- function(input, output,session) {

        fileData <- reactiveFileReader(1000,session,filePath = 'ddeLink.xlsm', readFunc = read_excel)

        output$data <- renderTable({
            fileData()
        })
}

The excel spreadsheet linkdde.xslm every five minutes updates. It is composed of 2 columns where only column b is updated. The excel file bellow:

The code works fine. That is, whenever the excel spreadsheet updates my app Shiny also updates the mmatrix above, which is the fileData ()result.

The fileData()is always updating. The fileData() is the matrix above.

But my question is: How do I access the values ​​of this mtrix, represented by the fileData () to create a plot that would be updated because the fileData () is updating. In other words I want to have a plot updating every 5 minutes using the 5 minutes fileData () matrix?

I did this:

output$data <- renderPlot({
 df<-as.data.frame(fileData())
 plot(df[,1])
})

But it didnt work.

Any help guys

Many thanks


回答1:


The below example seems to work, where the plot is updated when the Excel file is updated. Is this what you are looking for? If not, please describe further what you need.

library(shiny)
library(readxl)

ui <- fluidPage(
  mainPanel(
    uiOutput("data"),
    plotOutput("plot")
  )
)

server <- function(input, output,session) {
  fileData <- reactiveFileReader(1000,
                                 session,
                                 filePath = 'ddeLink.xlsx', 
                                 readFunc = read_excel)

  output$data <- renderTable({
    fileData()
  })

  output$plot <- renderPlot({
    df<-as.data.frame(fileData())
    plot(df[,2]) 
  })
}

shinyApp(ui, server)


来源:https://stackoverflow.com/questions/58774758/using-reactivefilereader-function-in-shiny

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!