trying to upload csv data on shiny app

Hi everyone!
I am a beginner, and I am trying to build a shiny app which lets me upload a csv file and then show me a histogram based on the data from that file.
I know how to write the code to upload the data, and separately how to show random data on histogram on shiny app, but unfortunately I cant do both, because I dont know how to connect the data from the csv to the histogram.
Can someone help me with that?

this is the code:
server <- function(input, output) {
output$contents <- renderTable({
data <- input$file1
if (is.null(data))
read.csv(data$datapath, header = input$header)
**trying to connect between the data and the functions
output$hist<-renderPlot({hist(data$dep_1, breaks=data$date)})

Thank you!

Here is some code that works for me. You need to replace the variable name (var_name) with whatever variable in the dataset you want to plot.

In this code, reactive and req work together to wait for the file up be "uploaded" and then it triggers the downstream code to run.


ui <- fluidPage(
  fileInput('csv', 'Input CSV', accept = '.csv'),

server <- function(input, output, session) {
  data <- reactive({
  output$hist <- renderPlot({
    hist(data()$var_name) # replace var name

shinyApp(ui, server)

Thank you so much!
One more question, I want my customer to enter an participant ID, which is connected to specific participant with specific data. With that ID I want to build a histogram which shows on x axis the dates and on Y axis the amount of a variable. how can I do that?
Thank you!

This is a different question, I think you should ask it on a new topic providing a proper reproducible example, relevant for the issue.

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