反应性数据框架

时间:2014-05-08 05:15:21

标签: r shiny ggvis

我想访问一个data.frame data,它在闪亮的反应函数中被读入R中。

data.frame

data=reactive({
data=read.table(sprintf("../tables/%s",input$dataset),sep="\t",h=T)
data$keys <- seq(1, nrow(data))  
data
})

我试图从另一个被动的ggvis图中调用data。特别是,我的tooltip_info函数将显示不属于ggvis图的列name

tooltip_info函数

tooltip_info <- function(x=NULL) {
    if(is.null(x)) return(NULL)
    key = x["keys"][[1]]
    data$name[key]
}   

反应性ggvis情节

    gv = reactive({
        ggvis(data, 
        props(
                x= ~b1, 
                y=~b2,
                key := ~keys
            )
        )+
        layer_point(
        props(
                fill=~as.factor(cluster), 
                shape=~annotation
            )
        )+
        tooltip(tooltip_info)
        })

server.ui

library(shiny)
library(ggvis)

shinyServer(function(input,output,session) { 

data=reactive({
data=read.table(sprintf("../tables/%s",input$dataset),sep="\t",h=T)
data$keys <- seq(1, nrow(data))  
data
})

tooltip_info <- function(x=NULL) {
    if(is.null(x)) return(NULL)
    key = x["keys"][[1]]
print(str(data))
}     
    gv = reactive({
        ggvis(data, 
        props(
                x= ~b1, 
                y=~b2,
                key := ~keys
            )
        )+
        layer_point(
        props(
                fill=~as.factor(cluster), 
                shape=~annotation
            )
        )+
        tooltip(tooltip_info)
        })
    observe_ggvis(gv,"daplot",session)
})

ui.r

library(shiny)


kos=list.files(path="../tables", pattern = "\\.txt")

shinyUI(fluidPage(
titlePanel("Comparing across Expression"),
  sidebarPanel(
    selectInput(inputId = "dataset",
                label = "Choose Dataset",
kos
                )    
    ),
mainPanel(
    ggvis_output("daplot")    
)
))

当我检查print(str(data)) data的结构时,它不是data.frame对象,而是给出了这个输出:

function ()  
 - attr(*, "observable")=Reference class 'Observable' [package "shiny"] with 9 fields
  ..$ .func           :function ()  
  .. ..- attr(*, "srcref")=Class 'srcref'  atomic [1:8] 6 15 10 1 15 1 6 10
  .. .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x10eb80bf0> 
  ..$ .label          : atomic [1:1] reactive({
    data = read.table(sprintf("../tables/%s", input$dataset), 
        sep = "\t", h = T)
    data$keys <- seq(1, nrow(data))
    data
})
  .. ..- attr(*, "srcfile")= chr ""
  ..$ .dependents     :Reference class 'Dependents' [package "shiny"] with 1 fields
  .. ..$ .dependents:Reference class 'Map' [package "shiny"] with 1 fields
  .. .. ..$ .env:<environment: 0x100eb10e0> 
  .. .. ..and 22 methods, of which 10 are possibly relevant:
  .. .. ..  clear, containsKey, get, initialize, keys, mset, remove, set, size, values
  .. ..and 14 methods, of which 2 are possibly relevant:
  .. ..  invalidate, register
  ..$ .invalidated    : logi FALSE
  ..$ .running        : logi FALSE
  ..$ .value          :'data.frame':    2097 obs. of  18 variables:
  .. ..$ key             : int [1:2097] 1 2 3 4 5 6 7 8 9 10 ...
  .. ..$ contig          : Factor w/ 2097 levels "K00012:K00012-000001-001:contig00008",..: 1 2 3 4 5 6 7 8 9 10 ...
  .. ..$ ko              : Factor w/ 1 level "K00012": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ gene            : Factor w/ 2097 levels "K00012:K00012:K00012-000001-001:contig00008-LEN:200",..: 1 2 3 4 5 6 7 8 9 10 ...
  .. ..$ gDNA.b1         : num [1:2097] 2.026 1.21 0.158 0.543 0.784 ...
  .. ..$ mRNA.b1         : num [1:2097] 3.226 0 0 0.102 0 ...
  .. ..$ mRNA.b2         : num [1:2097] 1.797 0 0 0.158 0.528 ...
  .. ..$ symbol          : Factor w/ 1 level "UGDH": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ name            : Factor w/ 1 level "UDPglucose 6-dehydrogenase [EC:1.1.1.22]": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ taxaid          : int [1:2097] 28068 28068 28216 28068 1049 75787 12960 1224 28068 2 ...
  .. ..$ genus           : Factor w/ 233 levels "","Achromobacter",..: 193 193 31 193 13 182 21 169 193 26 ...
  .. ..$ GLO             : Factor w/ 976 levels "10_105_194_286_338_352_379_429_469_547_551_561_581_613_626_629_642_662_702_816_832_963_1091_1227_2370_2745_12916_18297_21374_24"| __truncated__,..: NA NA 3
74 NA NA 959 NA 448 NA 607 ...
  .. ..$ NUM             : int [1:2097] NA NA 86 NA NA 63 NA 43 NA 34 ...
  .. ..$ glo_num         : int [1:2097] 1 1 86 1 1 63 1 43 1 34 ...
  .. ..$ newnames        : Factor w/ 1176 levels "","10_105_194_286_338_352_379_429_469_547_551_561_581_613_626_629_642_662_702_816_832_963_1091_1227_2370_2745_12916_18297_21374_24"| __truncated__,..: 114
1 1141 375 1141 987 960 995 449 1141 608 ...
  .. ..$ genus_annotation: Factor w/ 2 levels "annotated","notannotated": 1 1 2 1 1 2 1 2 1 2 ...
  .. ..$ cluster         : int [1:2097] 9 9 1 9 9 1 9 1 9 2 ...
  .. ..$ keys            : int [1:2097] 1 2 3 4 5 6 7 8 9 10 ...
  ..$ .visible        : logi TRUE
  ..$ .execCount      : int 1
  ..$ .mostRecentCtxId: chr "1452"
  ..and 15 methods, of which 3 are possibly relevant:
  ..  .updateValue, getValue, initialize
 - attr(*, "class")= chr "reactive"

0 个答案:

没有答案
相关问题