R: rhandsontable 不显示过滤后的反应内容
R: rhandsontable does not display filtered reactive content
我有一个显示 editable rhandsontable
并在绘图中显示 table 输出的 Shiny 应用程序。只要我将 "complete" 反应数据帧发送到 rhandsontable
一切都很好,但是当我想用 selectInput
值对显示的内容进行子集化时,应用程序中断并显示以下错误消息:
Listening on http://127.0.0.1:5362
Warning: Error in matrix: 'data' must be of a vector type, was 'NULL'
Stack trace (innermost first):
60: matrix
59:
58: do.call
57: hot_to_r
56: observerFunc [P:/Mango Engagement/00-CLAIMS/00-shiny-SPRINT3/20190211-shiny-broken-reactive-values-editable-table-plot.R#57]
1: runApp
ERROR: [on_request_read] connection reset by peer
关于如何进行的任何想法?在下面的脚本中,您可以通过 react_df()
的 commenting/uncommenting 定义重现该问题。
library(shiny)
library(rhandsontable)
library(dplyr)
library(ggplot2)
#### based on the SO code found here:
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)
正如@A.Suliman指出的那样,问题是在旧的 R 包上引起的。具有更新包的相同代码 运行 未返回任何错误。感谢您的帮助!
我有一个显示 editable rhandsontable
并在绘图中显示 table 输出的 Shiny 应用程序。只要我将 "complete" 反应数据帧发送到 rhandsontable
一切都很好,但是当我想用 selectInput
值对显示的内容进行子集化时,应用程序中断并显示以下错误消息:
Listening on http://127.0.0.1:5362
Warning: Error in matrix: 'data' must be of a vector type, was 'NULL'
Stack trace (innermost first): 60: matrix 59: 58: do.call 57: hot_to_r 56: observerFunc [P:/Mango Engagement/00-CLAIMS/00-shiny-SPRINT3/20190211-shiny-broken-reactive-values-editable-table-plot.R#57] 1: runApp
ERROR: [on_request_read] connection reset by peer
关于如何进行的任何想法?在下面的脚本中,您可以通过 react_df()
的 commenting/uncommenting 定义重现该问题。
library(shiny)
library(rhandsontable)
library(dplyr)
library(ggplot2)
#### based on the SO code found here:
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)
正如@A.Suliman指出的那样,问题是在旧的 R 包上引起的。具有更新包的相同代码 运行 未返回任何错误。感谢您的帮助!