Usage of variables from shiny output

147 views
Skip to first unread message

NG

unread,
Oct 27, 2015, 10:06:12 AM10/27/15
to Shiny - Web Framework for R
Hi there, 

I'm new in the field of R and shiny and try to build a simple app which should produce heat maps.

I used two selectizeInput-widgets to select cells and genes. That worked, but unfortunately only on Chrome. 
I could figure out that the problem seems to be the huge amount of genes out of which the user can select. Therefore, I tried to find a solution and integrated a text field with which the user can screen all available genes for matches (see picture). Afterwards, the user can select genes matching the search term (see picture).


This works very well but my problem is now how to save all selected genes because after a new search all selected genes will be discarded. Furthermore, I would like to introduce a "Clear Genes" button to reset the selection. The final step should be the calculation of a heat map of all saved selected genes. 


Here's my ui.R:


library(shiny)

library(gsubfn)

library(stringr)


shinyUI(fluidPage(

    titlePanel("Heat Map"),


  sidebarPanel(


selectizeInput(

   'e0', 'Cells:', choices = as.character(cells[,1]), multiple = TRUE,

selected = list("s1","s2","s3")),



    textInput("nameSearch", "Search for gene name", "SEPT"),


    uiOutput("selectUI"),    

    br(),

  

    actionButton("decrease","Clear Genes"),

    helpText("Save selected genes for subsequent calculation or clear data."),

    br(),

    

    uiOutput("actual_value"),

    br(),

    

submitButton("Submit Calculation"),

helpText("Please choose at least two cells and two genes to calculate a Heat Map!")


  ),

      mainPanel(

      textOutput("text"),

      plotOutput("expressionPlot")  

      )

  )

  )




And here my server.R:

shinyServer(function(input, output, session) {


searchResult<- reactive({
partners[grep(input$nameSearch, partners$name), ]
#subset(partners, grepl(input$nameSearch, partners$name))
})

output$searchResult <- renderTable({ 
searchResult()[,1]
})

output$selectUI <- renderUI({
    selectizeInput("var", "Click in and select genes",
                choices=as.character(searchResult()[,1]), multiple=TRUE, selected=list("SEPT1","SEPT2","SEPT3") )

})


blah <- reactive({
    selectizeInput("var", "Click in and select genes",
                choices=as.character(searchResult()[,1]), multiple=TRUE, selected=list("SEPT1","SEPT2","SEPT3") )
})


newBlah <- reactive({
autoInvalidate()
extract <- str_extract_all(blah(), 'selected>[a-zA-Z0-9_-]*<')
newExtract <- gsub('selected>','',extract)
gsub('<','', newExtract)
})



output$actual_value <- renderUI({
if (input$decrease >0) {
varNew <<- list("-")
}
else {
autoInvalidate()
varNew <<- newBlah()
}
autoInvalidate()
paste("Actual value is: ", varNew)
})


              
  output$expressionPlot <- renderPlot({
    blah <- data.matrix(dat0[input$partnerName,input$e0])
    if(nrow(blah)<2 || ncol(blah)<2) {
       # print error/ warning message
       output$text <- renderText({
       paste("Please select at least two cells and two genes!")
       })
    } else {
       output$text <- renderText({
       paste("")
       })
       heatmap(blah)
    }
  })

})


I would be very glad if someone could help me with this task! Many thanks :)

Joe Cheng

unread,
Oct 27, 2015, 6:21:17 PM10/27/15
to NG, Shiny - Web Framework for R
You should be able to search for a huge amount of gene names without resorting to adding a second textbox for searching, but you have to do it using server-side selectize--which is fortunately very easy to do. See the "Server-side selectize" section in this article:

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/51a6097c-c614-4a80-b829-9c08da43a542%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

NG

unread,
Oct 28, 2015, 6:11:59 AM10/28/15
to Shiny - Web Framework for R
Many thanks for your answer and tip! It solved my problem perfectly. I see, I have much to learn.
Reply all
Reply to author
Forward
0 new messages