动态更新ggvis闪亮的用户输入?

时间:2014-05-02 15:12:30

标签: r shiny ggvis

我是编程,R,闪亮和ggvis的初学者,试图根据用户输入包围反应数据更新。下面是一个闪亮的应用程序的可重现的示例,其中包含我正在尝试构建的类型的时间过程图。

应该运行应用程序,并应根据用户输入的更改进行更新。但是,仅当使用"映射"在ggvis()调用中调用x,y和size变量时,图才会更新。语法(=)。我的直觉是使用"设置"语法(:=)或(〜)运算符将有助于解决以下问题:

问题在于,当用户输入被更改并且新的绘图被发送到客户端时,不是生成新的绘图,而是希望数据点动态更新 - 在绘图中飞到新的(x ,y,尺寸)位置。

我还不熟悉ggvis如何将给定数据点(从数据帧的各列中取得的x,y和大小值)绑定到更新的数据点(在三个不同的列中)该数据帧的同一行)。目前ggvis中是否有功能允许我正在寻找的那种更新?

ui.R

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"))
      )
    )
  )
)

server.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)

})

1 个答案:

答案 0 :(得分:0)

我收到错误:找不到函数“ggvis_output”,ui.R的第20行应该是:

ggvisOutput("myDotPlot")),

observe_ggvis语句也有问题。 server.R的第40行