使用ggvis&Shiny-RStudio

时间:2018-12-14 14:24:26

标签: r shiny slider interactive ggvis

我已经看到了类似的问题和对该问题的回答,但是无法使用和{来实现两个input_sliders的输入来控制x轴的上下域。 中的{3}}。

我正在运行的脚本是:

Time <- aniso.df$Time
r_t <- r_t
trim.df <- data.frame(Time, r_t)
library(shiny)
library(ggvis)
library(googleVis)

for_plot <- structure(
list(Time = Time, 
   r_t = r_t
   ), .Names = c("Time", "r_t"), row.names = c(NA, -139L), 
class = c("data.table",  "data.frame")
)

runApp(list(
ui = bootstrapPage(
ggvisOutput("p"),
sliderInput("trimlim", "Trim last values:", min = 0, max = max(Time), value = max(Time), step= 1),
sliderInput("trimlim2", "Trim first values:", min = 0, max = max(Time), value = 0, step= 1)),

server = function(input,output, session) {
output$p <- renderGvis({
input$trimlim
input$trimlim2
for_plot[for_plot$Time<input$trimlim, for_plot$Time>input$trimlim2,] %>% ggvis(x = ~Time, y = ~r_t) %>% bind_shiny('p')
})
}
))

trim.df data.frame如下所示:

head(trim.df)
    Time         r_t
 1 0.00000 -0.05919221
 2 0.02442 -0.10030859
 3 0.04883  0.10410886
 4 0.07325  0.21235471
 5 0.09766  0.22980198
 6 0.12207  0.24670278

,但是此脚本无法运行。

为单个滑块修改脚本时,它可以正常运行。 (显示在此处):

Time <- aniso.df$Time
r_t <- r_t
trim.df <- data.frame(Time, r_t)
library(shiny)
library(ggvis)
library(googleVis)

for_plot <- structure(
list(Time = Time, 
   r_t = r_t
   ), .Names = c("Time", "r_t"), row.names = c(NA, -139L), 
class = c("data.table",  "data.frame")
)

runApp(list(
ui = bootstrapPage(
ggvisOutput("p"),
sliderInput("trimlim", "Trim last values:", min = 0, max = max(Time), value = max(Time), step= 1),
sliderInput("trimlim2", "Trim first values:", min = 0, max = max(Time), value = 0, step= 1)),

server = function(input,output, session) {
output$p <- renderGvis({
input$trimlim
input$trimlim2
for_plot[for_plot$Time<input$trimlim,] %>% ggvis(x = ~Time, y = ~r_t) %>% bind_shiny('p')
})
}
))

我已经尝试过for_plot的所有输入组合,但是一直遇到问题。第二个脚本添加了一个较高的装饰条,虽然格式不是最好的,但是没有问题,但是我希望有两个滑块来同时控制上下域。任何帮助将不胜感激。

谢谢!

0 个答案:

没有答案