R闪亮的ReactiveFileReader在第一次加载时不读取数据

时间:2018-03-18 14:14:47

标签: r shiny reactive-programming

我有一个基本的闪亮网页,我需要自动更新数据,所以我使用了reactiveFileReader,但是当我第一次打开页面时它对我不起作用。这是我写的代码的ui部分:

ui <- fluidPage(
      titlePanel("Some Heading"),
      tabsetPanel(
       tabpanel("TabA", fluid = TRUE,
                  sidebarPanel(
                    uiOutput('StFX'),
                    actionButton("UpdateFX", "UpdateView")
                  ),
                  mainPanel(
                    tableOutput("viewFX")
               ),
       tabpanel("TabB", fluid = TRUE,
                  sidebarPanel(
                    uiOutput('StCD'),
                    actionButton("UpdateCD", "UpdateView")
                  ),
                  mainPanel(
                    tableOutput("viewCD")
                  )
               )
      )
      )

这是代码的服务器部分:

server <- function(input, output, session){
       filedatafx <- reactiveFileReader(10000, session, "fx.csv", read.csv)
       filedatacd <- reactiveFileReader(10000, session, "cd.csv", read.csv)
       output$StFX = renderUI({
              mydata = filedatafx()
              choices = mydata$col1 #Fetching choices from a column of the data
              choices = unique(choices)
              selectInput('dropdownFX', 'Types', choices)
              })

       output$StCD = renderUI({
              mydata = filedatacd()
              choices = mydata$col1 #Fetching choices from a column of the data
              choices = unique(choices)
              selectInput('dropdownCD', 'Types', choices)
              })

       datasetInputFX <- eventReactive(input$updateFX, {
              mydata = filedatafx()
              ListOfST <- by(mydata,mydata[,"col1"], function(x) x) #Grouping data based on values in Col1.
              data.df <- data.frame(ListOfST[input$dropdownFX]) #Show values for the selected value in the dropdown.
              colnames(data.df) <- c("ColA", "ColB", "DP","ColE", "ColF", "ColG","ColA", "ColX", "ColY","ColZ")
              data.df["DP"] <- NULL #Some preprocessing of the other columns before rendering.
              return(data.df)
              }. ignoreNULL = FALSE)

       datasetInputCD <- eventReactive(input$updateCD, {
              mydata = filedatacd()
              ListOfST <- by(mydata,mydata[,"col1"], function(x) x) #Grouping data based on values in Col1.
              data.df <- data.frame(ListOfST[input$dropdownCD]) #Show values for the selected value in the dropdown.
              #Changing column names
              colnames(data.df) <- c("ColA", "ColB", "DP","ColE", "ColF", "ColG","ColA", "ColX", "ColY","ColZ")
              data.df["DP"] <- NULL #Some preprocessing of the other columns before rendering.
              return(data.df)
              }. ignoreNULL = FALSE)

       output$viewFX <- renderTable({datasetInputFX(). include.rownames = FALSE})
       output$viewCD <- renderTable({datasetInputCD(). include.rownames = FALSE})
          }

在第一次加载时,它给了我这个错误:

  

错误:'names'属性[10]的长度必须与vector [0]

的长度相同

我认为这是代码的colnames部分中的错误,因为它的长度为10.并且与响应式读取器的工作方式有关。当我单击更新视图更新表但总是出现在页面的第一次加载时,此错误消失。 (即使我在浏览器上点击刷新)

0 个答案:

没有答案