From 23f87181a5d5d8e5d9c74aa36df18f6dc664630f Mon Sep 17 00:00:00 2001 From: Elisa Loy <37096340+loye16@users.noreply.github.com> Date: Mon, 21 Aug 2023 12:36:16 -0400 Subject: [PATCH] Change load type Before these tabs only plotted .Rda files --- UIs/ui_binning_params.R | 2 +- servers/server_binning_params.R | 10 +++++++--- servers/server_plot_raster.R | 13 ++++++++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/UIs/ui_binning_params.R b/UIs/ui_binning_params.R index 9a8bb4c..60fe180 100644 --- a/UIs/ui_binning_params.R +++ b/UIs/ui_binning_params.R @@ -9,7 +9,7 @@ binning_params <- tabPanel( status = "danger", solidHeader = TRUE, title = "Choose a directory of raster data files", - helpText("We only accept .mat and .Rda format"), + helpText("We only accept .mat, .Rda, .csv formats"), shinyFiles::shinyDirButton("bin_chosen_raster", "Browse", ""), helpText("Loaded raster data: "), textOutput("bin_show_chosen_raster")), diff --git a/servers/server_binning_params.R b/servers/server_binning_params.R index 263d22f..709227d 100644 --- a/servers/server_binning_params.R +++ b/servers/server_binning_params.R @@ -13,9 +13,13 @@ observe({ req(input$bin_chosen_raster) # Set current directory name to the base directory rv$selected_rasters <- shinyFiles::parseDirPath(c(wd=rv$raster_base_dir), input$bin_chosen_raster) - rv$mat_raster_list <- list.files(rv$selected_rasters, pattern = "\\.mat$") - rv$rda_raster_list <- list.files(rv$selected_rasters, pattern = "\\.[rR]da$") - rv$raster_num_neuron <- length(rv$rda_raster_list) + #rv$mat_raster_list <- list.files(rv$selected_rasters, pattern = "\\.mat$") + #rv$rda_raster_list <- list.files(rv$selected_rasters, pattern = "\\.[rR]da$") + rv$raster_list <- list.files(rv$selected_rasters, + pattern = "\\.[rR]da$|\\.csv$|\\.mat$") + + rv$raster_num_neuron <- length(rv$raster_list) #- elisa + #rv$raster_num_neuron <- length(rv$rda_raster_list) }) diff --git a/servers/server_plot_raster.R b/servers/server_plot_raster.R index bbfd7d9..34deb38 100644 --- a/servers/server_plot_raster.R +++ b/servers/server_plot_raster.R @@ -25,17 +25,19 @@ observeEvent(list(rv$selected_rasters, rv$raster_cur_neuron),{ req(rv$raster_num_neuron) if(rv$raster_num_neuron > 0){ # Find the current file to view - rv$raster_cur_file_name <- rv$rda_raster_list[rv$raster_cur_neuron] + #rv$raster_cur_file_name <- rv$rda_raster_list[rv$raster_cur_neuron] + rv$raster_cur_file_name <- rv$raster_list[rv$raster_cur_neuron] #elisa # Load in the data and save time cols into matrix - #NeuroDecodeR::read_raster_data() - elisa - load(file.path(rv$selected_rasters, rv$raster_cur_file_name)) + raster_data <- NeuroDecodeR::read_raster_data(file.path(rv$selected_rasters, rv$raster_cur_file_name)) + #load(file.path(rv$selected_rasters, rv$raster_cur_file_name)) #elisa raster_df <- select(raster_data, starts_with("time.")) raster_matrix <- as.matrix(raster_df) # Reformat matrix and save as random variable rownames(raster_matrix) <- 1:dim(raster_matrix)[1] colnames(raster_matrix) <- gsub("time.", "", colnames(raster_matrix)) + colnames(raster_matrix) <- gsub("^(-?[0-9]+)_.*", "\\1", colnames(raster_matrix)) #Elisa rv$cur_raster_matrix <- raster_matrix } }) @@ -75,6 +77,11 @@ output$bin_PSTH <- renderPlot({ req(rv$cur_raster_matrix) # Create column means and turn into a df to plot cur_raster_col_means <- colMeans(rv$cur_raster_matrix, na.rm = FALSE) + + # Removing the ranges + + #raster_means_df <- data.frame(time = time, + # spike_mean_over_trials = cur_raster_col_means) raster_means_df <- data.frame(time = as.numeric(names(cur_raster_col_means)), spike_mean_over_trials = cur_raster_col_means)