How do I get row names as choices from interactive data in shiny?

Viewed 32

I have the whole code below

basically I have data.rds file and I want to get row names when I upload the data.rds file as interactive called data() then I want to get row names(data()) and show those row names as choices in the UI component.

I don't see any help how to do this. Thanks in advance for anyone who can help.

### Server


server = function(input, output,session) {

data <- reactive({
  file <- input$rds
  ext <- tools::file_ext(file$datapath)
  req(file)
  validate(need(ext == "rds", "Please upload a rds file"))
  readRDS(file$datapath)
})




observeEvent(input$foo, {
  updateSelectizeInput(session, 'foo', choices = rownames(data()), server = TRUE)
})

## Metadata

output$meta = renderDataTable({met()})

met = reactive({data()@meta.data})

output$mety <- downloadHandler(
  filename = function(){"thename.csv"}, 
  content = function(fname){
    write.csv(met(), fname)
  }
)




### PCA 



Dim_X = isolate(reactive({input$Dim_Y}))
Dim_Y = isolate(reactive({input$Dim_X}))

output$pcaplot<-renderPlot({
  input$RUN
isolate(DimPlot(data(), reduction = input$pca,pt.size=input$pt.size, dims = c(Dim_X(),Dim_Y()), label = TRUE, label.size = input$label.size, label.color = input$label.color, repel = T, group.by = NULL))
})



p <- reactive({
  input$RUN
isolate(DimPlot(data(), reduction = input$pca,pt.size=input$pt.size, dims = c(Dim_X(),Dim_Y()), label = TRUE, label.size = input$label.size, label.color = input$label.color, repel = T, group.by = NULL))
})

output$deptyu <- downloadHandler(
  file = "save.pdf" , # variable with filename
  content = function(file) {
    ggsave(p(), filename = file)
  })

}

# UI 

### PCA 


ui = fluidPage(
  tabsetPanel(
    tabPanel("File Input", fluid = TRUE,
             sidebarLayout(
               sidebarPanel(fileInput("rds", "File Upload", accept = ".rds")),
               mainPanel(
                 
                 tags$div(tags$p("Seurat Shiny App By Dietmann Lab is designed to view, edit and download Principal Components ,t-distributed stochastic neighbor embedding & Uniform Manifold Approximation and Projection Plots. It allows you to easily edit the cluster names and colors as well. Finally, it also allows for diiferential gene expression and average expression calculations. This is the first version so there will be continous development."), 
                          tags$h2("Types of Function Inegrated"), 
                          tags$h3("Dimensional Reduction Plot"), 
                          tags$p("Graphs the output of a dimensional reduction technique on a 2D scatter plot where each point is a cell and it's positioned based on the cell embeddings determined by the reduction technique. By default, cells are colored by their identity class (can be changed with the group.by parameter)."),
                          tags$h3("Dotplots"), 
                          tags$p("Intuitive way of visualizing how feature expression changes across different identity classes (clusters). The size of the dot encodes the percentage of cells within a class, while the color encodes the AverageExpression level across all cells within a class (blue is high)."),
                          tags$h3("Feature Plots"), 
                          tags$p("Colors single cells on a dimensional reduction plot according to a 'feature' (i.e. gene expression, PC scores, number of genes detected, etc.)"),
                          tags$h3("Average sand Differential Expression"),
                          tags$p("Returns averaged expression and differential values for each identity class"))
                 
               )
             )
    ),
    tabPanel("Metdata", fluid = TRUE,  sidebarLayout(
      sidebarPanel(downloadButton('mety',"Download Data")),
      fluidRow(column(7,shinycssloaders::withSpinner(dataTableOutput('meta'), size = 2, type = 8)), style = "max-height: 50vh; overflow-y: auto;" ))),
    tabPanel("Expression", fluid = TRUE, sidebarLayout(
      sidebarPanel(downloadButton('dept',"Download Data")),
      fluidPage(fluidRow(column(7,shinycssloaders::withSpinner(dataTableOutput('tab'), size = 2, type = 8 )), style = "max-height: 50vh; overflow-y: auto;" )))),
    tabPanel("Differential Expression", fluid = TRUE, sidebarLayout(
      sidebarPanel(downloadButton('depty',"Download Data")),
      fluidPage(fluidRow(column(7,shinycssloaders::withSpinner(dataTableOutput('diffy'), size = 2, type = 8)), style = "max-height: 50vh; overflow-y: auto;")))),
    
    tabPanel("Principal Component Analysis", fluid = TRUE,sidebarLayout(
      sidebarPanel( numericInput('Dim_X', 'Dimension X',1,min = 0, max = 50), 
                    numericInput('Dim_Y', 'Dimension Y',2,min = 0, max = 50),selectizeInput('pca', 'reduction.name',choices = c("pca")),
                    selectizeInput("foo", label = "foo",choices = NULL ),
                                   selectInput('label.color', 'Label Color',choices = c("red", "black", "blue")),
                                   numericInput("label.size", "Label Size", 4, min = 0, max = 10),
                                   numericInput("pt.size", "Point Size", 0.8, min = 0, max = 10),
                                   actionButton("RUN", "Make Changes"),
                                   downloadButton('deptyu',"Download")
                    ),
                    
                    mainPanel(fluidRow(column(6,plotOutput("pcaplot"))))))))
0 Answers
Related