我是编程、R、shiny 和 ggvis 的初学者,我试图围绕基于用户输入的反应式数据更新。下面是一个闪亮的应用程序的可重现示例,其中包含我正在尝试构建的类型的时间进程图。
该应用程序应该运行,并且应该根据用户输入的变化进行更新。但是,仅当使用“映射”语法 (=) 在 ggvis() 调用中调用 x、y 和 size 变量时,绘图才会更新。我的直觉是使用“设置”语法( := )或( ~ )运算符将有助于解决以下问题:
问题是,当用户输入发生更改时,不是生成一个新图,而是将新图发送到客户端,我希望数据点动态更新 - 飞越图到新的 (x,y,大小)位置。
我对 ggvis 如何将给定数据点(从数据帧的各个列中获取的 x、y 和大小值)绑定到更新的数据点(该数据同一行中的三个不同列)在语法上还不熟悉框架)。ggvis 中当前是否有允许我正在寻找的更新的功能?
用户界面
library(shiny)
library(ggvis)
shinyUI(pageWithSidebar(
headerPanel=headerPanel("Reactive Data Update Problem"),
sidebarPanel=sidebarPanel(
selectInput("timePoint",
"Choose Time Point:",
list("time1" = 1,
"time2" = 2
)
)
),
mainPanel=mainPanel(
tabsetPanel(
tabPanel('Plot',
ggvis_output("myDotPlot")),
tabPanel('Table',
dataTableOutput("myDataTable"))
)
)
)
)
服务器.R
library(shiny)
library(ggvis)
# Create sample dataset
time1x <- rexp(500, 2)
time1y <- rexp(500, 1)
time1s <- abs(log2(time1x/time1y))
time2x <- rexp(500, .02)
time2y <- rexp(500, .01)
time2s <- abs(log2(time2x/time2y))
myDataTable <- data.frame( "time1x" = time1x
, "time1y" = time1y
, "time1s" = time1s
, "time2x" = time2x
, "time2y" = time2y
, "time2s" = time2s
)
# Define paster functions allowing an input integer to represent a d.f column
xFormat <- function(timePoint) { paste("time", timePoint, "x", sep = "") }
yFormat <- function(timePoint) { paste("time", timePoint, "y", sep = "") }
sFormat <- function(timePoint) { paste("time", timePoint, "s", sep = "") }
# Define server logic necessary to produce plot
shinyServer(function(input, output, session){
myDotPlot <- reactive({
ggvis(myDataTable, props( x = as.name(xFormat(input$timePoint))
, y = as.name(yFormat(input$timePoint))
, size = as.name(sFormat(input$timePoint))
)
) + mark_point()
})
output$myDataTable = renderDataTable({myDataTable})
observe_ggvis(myDotPlot, 'myDotPlot', session)
})