代码之家  ›  专栏  ›  技术社区  ›  Kasia Kulma

r:rhandsontable不显示过滤后的反应性内容

  •  0
  • Kasia Kulma  · 技术社区  · 6 年前

    我有一个闪亮的应用程序显示一个可编辑的 rhandsontable 并在绘图中显示表格输出。只要我发送一个“完整的”反应性数据帧到 洗手间桌 但当我想将显示的内容 selectInput 值,应用程序将中断,并显示以下错误消息:

    倾听 http://127.0.0.1:5362

    警告:矩阵中的错误:“data”必须是矢量类型,为“null”

    堆栈跟踪(最里面的第一个): 60:矩阵 59: 58:打电话 57:热天 56:Observerfunc[P:/Mango Engagement/00-Claims/00-Shining-Sprint3/20190211 Shining Breaked Reactive Values可编辑表格绘图。r 57] 1:RunAPP

    错误:【请求读取】连接被对等方重置

    你对怎么做有什么想法吗?在下面的脚本中,您可以通过注释/取消注释 react_df() .

    library(shiny)
    library(rhandsontable)
    library(dplyr)
    library(ggplot2)
    
    #### based on the SO code found here: https://stackoverflow.com/a/52607643/6327771
    
    df <- data.frame(country = c(rep('US', 5), rep('UK', 5)),
               date = rep(as.Date(c('2018-01-01', '2018-02-01', '2018-03-01', '2018-04-01', '2018-05-01')), 2),
               val = rep(sample(6:8, size = 5, replace = T), 2))
    
    
    
    ui <- fluidPage(
      selectInput("country", "Choose the Country",
                  choices = df %>% unique() %>%  pull(country),
                  selected = 'US',
                  multiple = FALSE),
      rHandsontableOutput('table'), # editable table with bar heights
      plotOutput('plot')#, # bar plot that takes values from the drop-down menu and the editable table 
    )
    
    
    server <- function(input,output,session)({
    
    #### REACTIVE INPUT: SUBSETTED VERSUS COMPLETE DATA ####  
    ## subsetted version of react_df() 
    
    #  react_df <- reactive({
    #    df %>%
    #      filter(country == input$country)
    #  })
    
    ## complete version of react_df()   
      react_df <- reactive({df})
    
      values <- reactiveValues(data = NULL)
    
    
      observe({
        values$data <-react_df()
      })
    
    
      #observe the  table
      observe({
        if(!is.null(input$table))
          values$data <- hot_to_r(input$table)
      })
    
      # output the table 
      output$table <- renderRHandsontable({
        req(values$data)
        rhandsontable(values$data)
      })
    
    
    # update the plot  
      output$plot <- renderPlot({
        req(values$data)
        ggplot(values$data, aes(date, val)) +
          geom_line() +
          geom_point()
    
      })
    
    })
    
    shinyApp(ui = ui, server = server)
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Kasia Kulma    6 年前

    正如@A.Suliman指出的,问题是由旧的R包引起的。使用更新包运行的同一代码未返回任何错误。谢谢你的帮助!