Commit 3d2416a7 authored by Jean-Karim Heriche's avatar Jean-Karim Heriche

Sort values in single variable plot according to table sorting order.

parent e048a372
......@@ -414,8 +414,9 @@ server <- function(input, output, session) {
sep = input$sep,
quote = input$quote,
stringsAsFactors = FALSE)
rv$data[,"idx"] <- c(1:nrow(rv$data)) # Used to uniquely identify data points
rv$colsToHide <- c(rv$colsToHide, match("idx", colnames(rv$data)))
rv$data[,"id"] <- c(1:nrow(rv$data)) # Used to uniquely identify data points
rv$data[,"idx"] <- c(1:nrow(rv$data)) # Used to reorder data points
rv$colsToHide <- c(rv$colsToHide, match("id", colnames(rv$data)), match("idx", colnames(rv$data)))
rv$currentRows <- c(1:nrow(rv$data))
},
error = function(e) {
......@@ -426,39 +427,39 @@ server <- function(input, output, session) {
rv
})
# Info to display on hover
## Info to display on hover
observeEvent(input$colsOnHover, {
req(rv$data) ## Proceed only if file read
# Get index of each column
# Note: indexing starts at 0 but if row names are present they are in column 0
# so we don't use -1 to get the actual column indices.
## Get index of each column
## Note: indexing starts at 0 but if row names are present they are in column 0
## so we don't use -1 to get the actual column indices.
rv$colsOnHover <- match(input$colsOnHover, colnames(rv$data))
})
# Columns to hide
## Columns to hide
observeEvent(input$colsToHide, {
req(rv$data) ## Proceed only if file read
# Get index of each column
# Note: indexing starts at 0 but if row names are present they are in column 0
# so we don't use -1 to get the actual column indices.
req(rv$data) # Proceed only if file read
## Get index of each column
## Note: indexing starts at 0 but if row names are present they are in column 0
## so we don't use -1 to get the actual column indices.
rv$colsToHide <- match(input$colsToHide, colnames(rv$data))
})
# Columns to edit
## Columns to edit
observeEvent(input$colsToEdit, {
req(rv$data) ## Proceed only if file read
# Get index of each column
# Note: indexing starts at 0 but if row names are present they are in column 0
# so we don't use -1 to get the actual column indices.
req(rv$data) # Proceed only if file read
## Get index of each column
## Note: indexing starts at 0 but if row names are present they are in column 0
## so we don't use -1 to get the actual column indices.
rv$colsToEdit <- match(input$colsToEdit, colnames(rv$data))
})
# Group labels
## Group labels
observeEvent(input$groupLabels, {
req(rv$data) ## Proceed only if file read
# Get index of column
# Note: indexing starts at 0 but if row names are present they are in column 0
# so we don't use -1 to get the actual column indices.
req(rv$data) # Proceed only if file read
## Get index of column
## Note: indexing starts at 0 but if row names are present they are in column 0
## so we don't use -1 to get the actual column indices.
idx <- match(input$groupLabels, colnames(rv$data))
if(!is.null(idx) && !is.na(idx) && length(idx)>0) {
rv$clusters <- rv$data[,idx]
......@@ -473,6 +474,7 @@ server <- function(input, output, session) {
## Show the data table in the explorer (this one is not editable)
output$dataTable <- renderDT({
isolate({
req(rv$data)
datatable(rv$data[rv$currentRows,],
class = 'row-border hover',
......@@ -508,6 +510,7 @@ server <- function(input, output, session) {
)
)) %>%
formatStyle( 0, target= 'row', lineHeight='60%')
})
}, server = TRUE) # Server side processing required for large data tables
## Make a proxy to manipulate the table after it's been rendered
......@@ -527,21 +530,23 @@ server <- function(input, output, session) {
if(length(input$selectedVar) == 1) {
selectedCols[2] <- input$selectedVar
selectedCols[1] <- "idx"
## Reordering based on data table row order
D[input$dataTable_rows_all[1:nrow(D)],"idx"] <- c(1:nrow(D))
} else {
selectedCols <- input$selectedVar
}
if(length(selectedCols) > 0 && length(selectedCols) <= 2) {
p <- ggplot(data = D, aes_string(x = selectedCols[1], y = selectedCols[2], key = "idx")) +
p <- ggplot(data = D, aes_string(x = selectedCols[1], y = selectedCols[2], key = "id")) +
labs(x = eval(selectedCols[1]), y = eval(selectedCols[2])) +
geom_point(colour = "grey") +
coord_cartesian(expand = TRUE)
if(!is.null(rv$clusters)) {
p <- p + geom_point(aes(colour = factor(clusters)), alpha = 0.3) +
p <- p + geom_point(aes(colour = factor(clusters)), alpha = 0.5) +
scale_colour_brewer(palette = 'Set1') +
theme(plot.title = element_blank(), legend.title = element_blank())
}
p <- p + geom_point(data = D[rv$selectedRows,],
aes_string(x = selectedCols[1], y = selectedCols[2], key = "idx"),
aes_string(x = selectedCols[1], y = selectedCols[2], key = "id"),
colour = "black")
ggplotly(p, tooltip = "none") %>% layout(legend = list(orientation = "v", x = 1, y = 0.8)) %>%
config(p = ., staticPlot = FALSE, doubleClick = "reset+autosize", autosizable = TRUE, displayModeBar = TRUE,
......@@ -552,7 +557,6 @@ server <- function(input, output, session) {
## Interactions with the plot
observe({
req(rv$data)
df <- rv$data
selectedCols <- c(NULL, NULL)
......@@ -565,14 +569,11 @@ server <- function(input, output, session) {
## Get indices of data points in selected area (Box and Lasso Select tool)
if(input$menu == "explore") { # Ensure we already have a plot
brush <- event_data("plotly_selected")
if(!is.null(brush)) {
rv$currentRows <- brush$pointNumber + 1
}
## Get indices of data points in zoomed-in/out area
zoom <- event_data("plotly_relayout")
if(!is.null(zoom) ) {
## Take care of cases where range is on one axis only
if (!is.null(zoom[['xaxis.range[0]']])) {
......@@ -604,7 +605,6 @@ server <- function(input, output, session) {
if(input$menu == "explore") { # Ensure we already have a plot
hover <- event_data("plotly_hover")
if(is.null(hover)) {
# empty <- data.frame(matrix(NA, nrow = 1, ncol = length(c(input$selectedVar, input$colsOnHover)), dimnames = list("", c(input$selectedVar, input$colsOnHover))))
head(rv$data[,c(input$selectedVar, input$colsOnHover)], n = 0)
} else {
rv$data[unlist(hover$key), c(input$selectedVar, input$colsOnHover)]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment