Skip to content

Commit b04031c

Browse files
committed
Add data tab
1 parent 3e0c8f4 commit b04031c

1 file changed

Lines changed: 56 additions & 7 deletions

File tree

app.R

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ ui <- fluidPage(
104104
tabPanel("Code",
105105
code_generation_ui("code_gen")
106106
),
107+
tabPanel("Data",
108+
fluidRow(
109+
column(12,
110+
div(style = "overflow-x: auto;",
111+
tableOutput("data_preview")
112+
),
113+
downloadButton("download_data", "Transformed Data")
114+
)
115+
)
116+
),
107117
tabPanel("About",
108118
titlePanel("DataMap: a portable app for visualizing data matrices v0.1"),
109119
img(src = "heatmap.png", width = "375px", height = "300px"),
@@ -707,13 +717,52 @@ col_annotation_for_heatmap <- reactive({
707717
height_for_plots # Use our reactive
708718
)
709719
code_gen_results <- code_generation_server(
710-
"code_gen",
711-
file_data,
712-
transform_data,
713-
heatmap_results,
714-
pca_results,
715-
tsne_results
716-
)
720+
"code_gen",
721+
file_data,
722+
transform_data,
723+
heatmap_results,
724+
pca_results,
725+
tsne_results
726+
)
727+
728+
output$data_preview <- renderTable({
729+
req(current_data())
730+
data <- current_data()
731+
732+
# Ensure data is a data frame
733+
if(!is.data.frame(data)) {
734+
data <- as.data.frame(data)
735+
}
736+
737+
# Limit to 30 rows and 30 columns
738+
max_rows <- min(30, nrow(data))
739+
max_cols <- min(30, ncol(data))
740+
741+
# Get the row indices and column indices
742+
row_indices <- seq_len(max_rows)
743+
col_indices <- seq_len(max_cols)
744+
745+
# Create a preview version of the data
746+
preview_data <- data[row_indices, col_indices, drop = FALSE]
747+
748+
# Return the preview with row names preserved
749+
preview_data
750+
}, rownames = TRUE, colnames = TRUE, bordered = TRUE, width = "100%",
751+
digits = 3, align = 'c')
752+
753+
754+
# Download handler for the data
755+
output$download_data <- downloadHandler(
756+
filename = function() {
757+
paste0("transformed_data-", format(Sys.time(), "%Y%m%d-%H%M%S"), ".csv")
758+
},
759+
content = function(file) {
760+
data <- current_data()
761+
write.csv(data, file, row.names = TRUE)
762+
}
763+
)
764+
765+
717766
}
718767

719768
# Run the application

0 commit comments

Comments
 (0)