How can I print tops (print[:]) according user preference with slide bar?

Viewed 46

How can i run a r shiny app, which print the top features based on user's choice?

I tried the following but I want the user to select, not putting it manually the top 3 for example

library(KEGGgraph)
library(xml2)
library(Rgraphviz)
ui <- fluidPage(
  
 sidebarLayout(
          sliderInput("range", 
                  label = "Range of interest:",
                  min = 0, max = 10, value = c(0, 100))
    ), 
    
    
    mainPanel( 
            tabsetPanel(type = "tabs",
                  tabPanel("Plots", plotOutput(outputId="genePlot", width = 1300, height=900)),
                  tabPanel("Edges", verbatimTextOutput("out_tops")),
                  tabPanel("Compounds", tableOutput("out_compounds")))
    )
  )
)
server <- function(input, output) {
output$out_tops <- renderPrint({
 mapkGall <- parseKGML2Graph(read_xml(sprintf("%s.xml", input$geneInput)), genesOnly=FALSE)
    
    mapkGsub <- subGraphByNodeType(mapkGall, "gene")
    
    graphs <- list(mapk=mapkGsub, wnt=mapkGall)
    merged <- mergeGraphs(graphs)
    merged
    outs <- sapply(edges(merged), length) > 0
    ins <- sapply(inEdges(merged), length) > 0
    ios <- outs | ins
    mapkGoutdegrees <- sapply(edges(mapkGall), length)
    mapkGindegrees <- sapply(inEdges(mapkGall), length)
    topouts <- sort(mapkGoutdegrees, decreasing=T)
    topins <- sort(mapkGindegrees, decreasing=T)
    if(require(org.Hs.eg.db)) {
      top_nodes_out <- translateKEGGID2GeneID(names(topouts))
      
      
      
      tmp <- c()
      
      for (i in top_nodes_out) {
        if (is.na(mget(sprintf("%s",i),  org.Hs.egSYMBOL, ifnotfound = NA))) {
          tmp <- append(tmp,sprintf("%s",i))
        }
        else {
          tmp <- append(tmp,mget(sprintf("%s",i),  org.Hs.egSYMBOL))
        }
      }
      nodesNames_outs <- sapply(tmp, "[[",1)
    } else {
      nodesNames_outs <- names(topouts)
    }

how can I let the user specify the printings by the slider bar?


    names(nodesNames_outs) <- names(topouts)
    print("top genes with out connections")
    print(nodesNames_outs[1:3])   ### Here like something for the slider bar print[:,sliderbar$input]

I would like not to print manually the top 3 but the user to select how many he wants. the code should sort the top genes and print them accordingly when user uses the slidebar Can you please suggest something?

0 Answers
Related