
[英]Shiny: ignoreNULL not working when the eventReactive function take output from another eventReactive function as input?
[英]The eventReactive() function from the shiny package is not working rightly
下面,我试图让破折号响应用户输入的变化。 有日期范围值、下拉菜单和复选框。 当任何默认功能更改时,由于更改,应该有一个新的图形和相应的结果。
下面的代码使用 eventReactive() function 创建一个反应组件 - "" bike_orderlines_data_filtered_tbl()。
bike_orderlines_data_filtered_tbl <- eventReactive(
eventExpr = input$apply,
valueExpr = {
bike_orderlines_tbl %>%
filter(order_date %>% between(left = input$date_range[1],
right = input$date_range[2])) %>%
filter(category_1 %in% input$checkbox_category_1) %>%
filter(category_2 %in% input$picker_category_2)
# Filtering code goes here
},
ignoreNULL = FALSE
)
但是,当我在下面的代码中调用反应组件时
renderPlotly(expr = {
geo_plot_tbl <- reactive({
bike_orderlines_data_filtered_tbl() %>%
group_by(state) %>%
summarise(total_revenue = sum(total_price)) %>%
ungroup() %>%
right_join(germany_sf, by = c("state" = "VARNAME_1")) %>%
mutate(total_revenue = ifelse(is.na(total_revenue), 0, total_revenue)) %>%
mutate(label_text = str_glue("State: {state}
Revenue: {format_to_euro(total_revenue)}")) %>%
st_as_sf()
})
plot_ly(geo_plot_tbl(),
split = ~NAME_1,
color = ~total_revenue,
colors = "Blues",
stroke = I("black"),
hoverinfo = 'text',
text = ~label_text,
hoveron = "fills",
showlegend = FALSE)
})
有某种反应正在进行,但现在当复选框、数据范围和下拉菜单发生变化时会产生新的结果。
提前致谢
当我尝试将普通的 dplyr function 与 usung shiny 反应性组件一起使用时 - 即普通的 dataframe,这是一种动态结果,它是音符反应性的。
我建议您尝试以下选项之一:
将geo_plot_tbl
移出renderPlotly
反应块。
geo_plot_tbl <- reactive({ bike_orderlines_data_filtered_tbl() %>% group_by(state) %>% summarise(total_revenue = sum(total_price)) %>% ungroup() %>% right_join(germany_sf, by = c("state" = "VARNAME_1")) %>% mutate(total_revenue = ifelse(is.na(total_revenue), 0, total_revenue)) %>% mutate(label_text = str_glue("State: {state} Revenue: {format_to_euro(total_revenue)}")) %>% st_as_sf() }) renderPlotly(expr = { plot_ly(geo_plot_tbl(), split = ~NAME_1, color = ~total_revenue, colors = "Blues", stroke = I("black"), hoverinfo = 'text', text = ~label_text, hoveron = "fills", showlegend = FALSE) })
不reactive
数据。
renderPlotly(expr = { geo_plot_tbl <- bike_orderlines_data_filtered_tbl() %>% group_by(state) %>% summarise(total_revenue = sum(total_price)) %>% ungroup() %>% right_join(germany_sf, by = c("state" = "VARNAME_1")) %>% mutate(total_revenue = ifelse(is.na(total_revenue), 0, total_revenue)) %>% mutate(label_text = str_glue("State: {state} Revenue: {format_to_euro(total_revenue)}")) %>% st_as_sf() plot_ly(geo_plot_tbl, split = ~NAME_1, color = ~total_revenue, colors = "Blues", stroke = I("black"), hoverinfo = 'text', text = ~label_text, hoveron = "fills", showlegend = FALSE) })
供参考,
ifelse(is.na(total_revenue), 0, total_revenue)
可以替换为
coalesce(total_revenue, 0)
为了(imo)更容易阅读。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.