【发布时间】:2015-05-20 07:30:35
【问题描述】:
基于我的这个问题:R ggvis interactive slider for calculating y values (e.g. for background correction),我想使用几个ggvis 滑块来修改一个背景校正。
library("dplyr")
library("ggvis")
library("lubridate")
data <- data.frame(timestamp = Sys.time() - hours(10:1),
signal = rnorm(10),
temperature = rnorm(10),
secondParameter = rnorm(10))
# mySliderA works fine
mySliderA <- input_slider(0, 2, value = 0, step = 0.1, label = "T-correction",
map = function(x) data$signal - x * data$temperature)
# mySliderB wants to add a second parameter to the calculation based on mySliderA, this fails.
mySliderB <- input_slider(0, 2, value = 0, step = 0.1, label = "P2-correction",
map = function(x2) mySliderA - x2 * data$secondParameter )
data %>%
ggvis() %>%
layer_paths(x = ~timestamp, y = ~signal, stroke := "darkgreen") %>%
layer_paths(x = ~timestamp, y = ~temperature, stroke := "red") %>%
# layer_paths(... y = mySliderA, ...) # would work, but:
layer_paths(x = ~timestamp, y = mySliderB, stroke := "darkblue")
# does not.
如何让第二个滑块工作?可能,我必须以不同的方式链接 mySliderA-calculated 值,但我不知道如何。
【问题讨论】: