2016-06-20 17 views
1

我需要允许用户上传文件以定义在应用程序中呈现的网络。rcytoscapejs:变量参数 - 'renderGraph'功能不可用

我想改变参数重新渲染是通过一个特殊的光泽github上套餐的“rcytoscapejs”部署一个互动的闪亮图:https://github.com/cytoscape/r-cytoscape.js/tree/master

虽然图形部署精细,我的问题是,它可以只能从UI部署,独立于服务器...

g<-createCytoscapeJsNetwork(nodeData = nodes, edgeData = edge) 
#ui.R 
dashboardBody(
    sliderInput(inputId="num", label="Choose coef", value=2, min=1, max=3), 
    rcytoscapejs(g$nodes, g$edges) 
) 

正如你可以看到这是从服务器完全公正的,当我试图通过这样的事情来实现服务器中的代码:

#ui.R 
graphOutput("graph") 
#server.R 
output$graph<-renderGraph({rcytoscapejs(g$nodes, g$edges)}) 

我已经试过“graphOutput”和“renderGraph”,但功能似乎并不存在...

我尝试下载从GitHub上的“renderGraph”。

devtools::install_github("mfontcada/renderGraph"); 
Downloading GitHub repo mfontcada/[email protected] 
from URL https://api.github.com/repos/mfontcada/renderGraph/zipball/master 
Error: Does not appear to be an R package (no DESCRIPTION) 

但是,这包是0.1版本,从2014年起一直没有更新......

所以,最后我的问题是我怎么可以改变的东西,驻留在“ui.R参数“代码?

类似如下,(取自文件上传代码:http://shiny.rstudio.com/gallery/file-upload.html):

server <- function(input, output) { 
    dataInput <- eventReactive(input$choices, { 
    inFile <- input$file1 
    if (is.null(inFile)) 
     return(NULL) 
     read.csv(inFile$datapath, header = input$header, sep = input$sep, quote = input$quote) 
    createCytoscapeJsNetwork(nodeData = nodes, edgeData = edge) 
    }) 
    } 

#ui.R 
actionButton("choices", "Run analyses"), 
fileInput('file1', 'Choose file to upload', 
      accept = c(
      'text/csv', 
      'text/comma-separated-values', 
      'text/tab-separated-values', 
      'text/plain', 
      '.csv', 
      '.tsv' 
     ), 
rcytoscapejs(dataInput()$nodes, dataInput()$edges), 

当然这将返回为一个不能改变ui.R脚本作为这样内参数的错误....

有关如何规避此问题的任何提示?

回答

1

整理出来与功能renderRcytoscapejs服务器和rcytoscapejsOutput用于UI还必须节约的类数据文件的被读入的反应性值与read.csv与分离物():

library(shinydashboard) 
library(rcytoscapejs) 
p1<-cor(t(E.rna_small[1:20,1:20]),use="p") #correlations taken from sample of matrix 
library(graph) #as per P Shannon's help must convert to way that is compatible with RCyjs 
library(RCyjs) 
library(igraph) 
g<-igraph.to.graphNEL(simplify(graph_from_adjacency_matrix(p1, weighted=T))) 
edge<-as.data.frame(get.edgelist(simplify(graph_from_adjacency_matrix(p1, weighted=T)))) 
colnames(edge)<-c("source", "target") 
nodes<-cbind(id=colnames(p1), name=rownames(p1)) 
class(nodes) 
nodes<-as.data.frame(nodes) 
b<-createCytoscapeJsNetwork(nodeData = nodes, edgeData = edge) 
uiactual <- dashboardPage(
    dashboardHeader(title="zoom"), 
    dashboardSidebar(menuItem(
        checkboxInput('header', 'Header', TRUE), 
        radioButtons('sep', 'Separator', 
           c(Comma=',', 
            Semicolon=';', 
            Tab='\t') 
           )), 

        menuItem(p('If you want a sample .csv or .tsv file to upload,', 
        'you can first download the sample', 
        a(href = 'mtcars.csv', 'mtcars.csv'), 'or', 
        a(href = 'pressure.tsv', 'pressure.tsv'), 
        'files, and then try uploading them.' 
        ))), 
    dashboardBody(
    sliderInput(inputId="num", label="Choose coef", value=2, min=1, max=3), 
    rcytoscapejsOutput("g3plot"), 
    fileInput('file1', 'Choose file to upload', 
       accept = c(
       'text/csv', 
       'text/comma-separated-values', 
       'text/tab-separated-values', 
       'text/plain', 
       '.csv', 
       '.tsv' 
      ) 
    ) 
) 
) 

    serveractual <- function(input, output) { 
    g3 <- reactive({ 
     inFile <- input$file1 
     if (is.null(inFile)) 
     return(NULL) 

     isolate(t<-read.table(inFile$datapath, header = T, 
          sep = "\t")) 
     #t<-for(i in colnames(t)){ 
     # as.numeric(t[,i]) 
     #} 

     p1<-cor(t(t),use="p") #correlations taken from sample of matrix 
     simplify(graph_from_adjacency_matrix(p1, weighted=T)) 
     edge<-as.data.frame(get.edgelist(simplify(graph_from_adjacency_matrix(p1, weighted=T)))) 
     colnames(edge)<-c("source", "target") 
     nodes<-cbind(id=colnames(p1), name=rownames(p1)) 
     nodes<-as.data.frame(nodes) 
     createCytoscapeJsNetwork(nodeData = nodes, edgeData = edge) 
    }) 


    output$g3plot = renderRcytoscapejs({ 
     rcytoscapejs(g3()$nodes, g3()$edges) 
    }) 

    } 
shinyApp(uiactual, serveractual)