Rendering data table and histogram

I'm trying to create an app that allows users to upload data and then use the data in a histogram. But I'm having trouble getting the data table to display for users, and then using a specific column within the dataset to manipulate the histogram. Here's the code I have so far:

library(shiny)
ui <- fluidPage(
  titlePanel("HD App"),
  sidebarLayout(
    sidebarPanel(
      fileInput("file1", "Choose a File",
                accept = c(".txt",
                           ".tsv"),
                buttonLabel = "Browse...",
                placeholder = "No file selected"),
      
      sliderInput(inputId = "num",
                  label = "Subset Data",
                  value = 1500, min = 1, max =3000),
      actionButton("reset", "Reset")
    ),
    mainPanel(
      DT::dataTableOutput("contents"),
      plotOutput("hist")
    ))
)

So I've figured out how to upload the data so far (it's a .txt file of a data table). But I want to render the data using DT::dataTableOutput, but I haven't been able to figure it out so far. I also want to make a histogram, that changes based on the frequency of the first column in the data table (the first column is weight).

Here is a very simple version of the kind of thing I think you want to do. Since you say you already know how to read in the data, I just made a simple data frame inside of the server section of the app.

library(shiny)
library(DT)
library(ggplot2)
ui <- fluidPage(
  titlePanel("Title"),
  mainPanel(
    dataTableOutput("TableOut"),
    plotOutput("Histo")
  )
)

server <- function(input, output) {
  DF <- data.frame(Name = LETTERS[1:10], Value = rnorm(20), Value2 = runif(20))
  output$TableOut <- renderDataTable({
    DF
  })
  output$Histo <- renderPlot({
    ggplot(DF, aes(Value)) + geom_histogram(binwidth = 0.2, 
                                            fill = "skyblue", color = "white")
  })
  
}

shinyApp(ui = ui, server = server)

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