简体   繁体   English

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

[英]updating ggvis shiny user input dynamically?

I am a beginner to programming, R, shiny, and ggvis, trying to wrap my head around reactive data updating based on user input. 我是编程,R,闪亮和ggvis的初学者,试图根据用户输入包围反应数据更新。 Below is a reproducible example of a shiny App containing a time course plot of the type I am trying to build. 下面是一个闪亮的应用程序的可重现的示例,其中包含我正在尝试构建的类型的时间过程图。

The app should run, and should update upon the change of user input. 应用程序应该运行,并应根据用户输入的更改进行更新。 However, the plot only updates when the x, y, and size variables are called in the ggvis() call using the "mapping" syntax ( = ). 但是,仅当使用“mapping”语法(=)在ggvis()调用中调用x,y和size变量时,绘图才会更新。 My intuition is that the use of the "setting" syntax ( := ) or the ( ~ ) operator would help solve the following problem: 我的直觉是使用“设置”语法(:=)或(〜)运算符将有助于解决以下问题:

The problem is that instead of a new plot being generated when the user input is changed, and that new plot being sent to the client, I would like the data points to update dynamically - fly across the plot to their new (x,y,size) position. 问题是,当用户输入被更改时,而不是新的绘图被发送到客户端,我希望数据点动态更新 - 飞过绘图到新的(x,y,大小)位置。

I'm not yet syntactically comfortable with how ggvis binds a given data point (with x, y, and size values taken from individual columns of a data frame) to an updated data point (of three different columns in the same row of that data frame). 我还不熟悉ggvis如何将给定数据点(从数据帧的各列中取得的x,y和大小值)绑定到更新的数据点(该数据的同一行中的三个不同列)帧)。 Is there currently functionality in ggvis that allows for the kind of update I am looking for? 目前ggvis中是否有功能允许我正在寻找的那种更新?

ui.R 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 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)

})

I get an error : could not find function "ggvis_output", line 20 of ui.R should be: 我收到一个错误:找不到函数“ggvis_output”,ui.R的第20行应该是:

ggvisOutput("myDotPlot")),

There is also something wrong with the observe_ggvis statement. observe_ggvis语句也有问题。 Line 40 of server.R server.R的第40行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM