r - 根据绘图框值更新数据框表值
问题描述
time
我有一个显示数据框的列和amount
的情节图df
。
东风:
id time amount category
1 2018-03-22 15:22:00 78 g1
2 2018-03-22 15:30:00 77 g1
...
34 2018-03-23 01:00:00 82 k3
...
该图是一个动画,因此该图逐步出现,如本例 ( https://plot.ly/r/cumulative-animations/#cumulative-lines-animation ) 中的Cumulative Lines Animation部分。我无法发布我的编码,但它看起来与此类似。
来自网站的编码:
library(plotly)
accumulate_by <- function(dat, var) {
var <- lazyeval::f_eval(var, dat)
lvls <- plotly:::getLevels(var)
dats <- lapply(seq_along(lvls), function(x) {
cbind(dat[var %in% lvls[seq(1, x)], ], frame = lvls[[x]])
})
dplyr::bind_rows(dats)
}
d <- txhousing %>%
filter(year > 2005, city %in% c("Abilene", "Bay Area")) %>%
accumulate_by(~date)
p <- d %>%
plot_ly(
x = ~date,
y = ~median,
split = ~city,
frame = ~frame,
type = 'scatter',
mode = 'lines',
line = list(simplyfy = F)
) %>%
layout(
xaxis = list(
title = "Date",
zeroline = F
),
yaxis = list(
title = "Median",
zeroline = F
)
) %>%
animation_opts(
frame = 100,
transition = 0,
redraw = FALSE
) %>%
animation_slider(
hide = T
) %>%
animation_button(
x = 1, xanchor = "right", y = 0, yanchor = "bottom"
)
现在我想在绘图旁边显示一个动态表,该表显示我的数据框与当前绘制时间有关的值。
所需的输出(如上图所示):
id 34
amount 82
category k3
此表输出应与绘图同时更新,始终显示当前时间的值(滑块的值),这是函数的frame
属性plotly()
所以关键问题是我需要访问动画滑块的值,但函数没有 id,所以我不能调用它。
知道如何获得滑块值吗?或者是否有另一种方法可以将动画连接到表格以实现我的目标?
解决方案
推荐阅读
- python - 图像未使用 django 从数据库加载到网页上
- typescript - TS2307 - 如何在 Angular 9 中使用我自己的库?
- java - 有没有办法以字符串格式从 XML 文件中获取查询?
- sql - 根据另一列中的存在更新列
- security - OAuth2 流程:通过重定向发送身份验证代码的原因
- mysql - xcom_push 总是抛出 Invalid utf8mb4 字符串警告 - Airflow 1.10.9
- ios - 如何在 iOS 的 AV 播放器中设置自定义标题
- javascript - 如何根据其他循环中的变量创建定时循环?
- python - 使用 Python Selenium 下载文件
- angular - 在 Angular/Typescipt 中,通用调用和 .. as Casting 之间有什么区别?特别是对于 HttpClient