Hi,
I am using the R shiny to show my dataset based on the case (Shiny - Basic DataTable) to show the outputs based on the user's query column inputs.
However, one column('Feature') have multiple strings separated by comma(,). In this case, is it possible to sort the unique strings in the column and set all the options as input for sorting?
Thank you so much for your help!
My example input table(For a specific row it may have multiple features in the Feature
column)
Chrom | Start | End | Dataset | Feature |
---|---|---|---|---|
chr1 | 136895 | 136895 | AML | promoter_2000,promoter_1000,cpg_shore |
chr1 | 181286 | 181286 | AML | promoter_2000 |
The snapshot for the output for my code below. You can see the options are still comma-separated like promoter_2000,promoter_1000,cpg_shore
, but I want the options be promoter_2000
, promoter_1000
, cpg_shore
and show corresponding results.
My code ui.R
:
library(ggplot2)
library(data.table)
fluidPage(titlePanel("Test"),
title = "Test",
fluidRow(
column(4,
selectInput("Feature",
"Feature:",
c("All",
unique(as.character(data$Feature))))
)
),
# Create a new row for the table.
DT::dataTableOutput("table")
)
server.R
library(ggplot2)
library(DT)
function(input, output) {
output$table <- DT::renderDataTable(DT::datatable({
df <- data
columns = names(df)
if (input$Feature != "All") {
df <- df[df$Feature == input$Feature]
}
df
},
}