Plotting based on row selection in Shiny

Hi,

I am trying to create an app that can plot data within files, the user will need to upload the data contained in single files, and an additional single file (tally) that contains a summary information of all other files, basically the table created from the tally file will represent each data file (i.e. each row will reflect a single file), when the user click on each row, data will be plotted for that specific file. I have tried but I can't seem to get it to work, could someone have a look at the code and tell me where I went wrong.

Thanks.

library(plotly)
library(shiny)
library(DT)

ui <- fluidPage(titlePanel("Plotter"),
tabsetPanel(
#--------------------------------------------------------------------------------------

              tabPanel("Data Upload",
                       fluidRow(sidebarLayout(sidebarPanel(                          

                         h4(strong('Upload Tally')),
                         
                         radioButtons("fileType1", "",
                                      choices = list("xlsx" = 1, "csv" = 2),
                                      selected = 2,
                                      inline = TRUE),
                         
                         fileInput("Tally", "Select File",
                                   multiple = FALSE,
                                   accept = c(".csv", ".xls", ".xlsx")),
                         hr(style="border-color: grey"),
                         
                         #-------------------------------------------------------------------                                 
                         
                         h4(strong('Upload Dents')),
                         
                         radioButtons("fileType2", "",
                                      choices = list("xlsx" = 1, "csv" = 2),
                                      selected = 2,
                                      inline = TRUE),
                         
                         fileInput("Dents", "Select File",
                                   multiple = T,
                                   accept = c(".csv", ".xls", ".xlsx")),
                         
                         
                       ),
                       #------------------------------------------------------------------------------------------------------------------                               
                       mainPanel(
                         h3('Profile'),
                         plotlyOutput("Raw3D")
                         
                       ))),
                       
                       hr(style="border-color: grey"),
                       
                       fluidRow(
                         h3('List'),
                         DT::dataTableOutput("contents")))
              
              
                             ))

################################################################################

server <- shinyServer(function(input, output, session) {

#---------------------- Read data -------------------------------------------------------------------------------------------------------------------

Tally_Data <- reactive({

req(input$Tally)

read.csv(input$Tally$datapath, header = T, sep = ",")

}) # end of tally data upload

output$contents <- renderDataTable({
datatable(Tally_Data(), selection = c("single"),
options = list(columnDefs = list(list(className = "dt-center", targets = "_all"))))
})

#-------------------------------------------------------------------------------------------------------------------

Data <- reactive({
req(input$Dents)
lst <- list()
lst <- lapply(input$Dents$datapath, read.table, header=TRUE, sep=",")
})

observe({
req(input$Tally_rows_selected)
selRow <- input$Tally_rows_selected

output$Raw3D <- renderPlotly({

Depth <- Data(selRow)[1:nrow(Data(selRow)),2:ncol(Data(selRow))]

plot_ly(z = as.matrix(Depth), type = "heatmap", colorscale = 'Jet')

})

})

}) # end of server

shinyApp(ui, server)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.