Dear all,
I hope you are all doing well! I am very new to this community and to Rstudio in general.
I really enjoy using R and Shiny, but find some difficulties reaching my objective.
My use case is, I believe, very simple. I want a user to be able to upload a CSV file containing a few thousands lines and a few columns (let's say only two columns so far, one entitled "sexe", corresponding to the individual's gender, and the other entitled "SISEDisc", corresponding to the individual's choosen graduate discipline).
Once uploaded, I want the user to be able to get a few simple diagrams (variable proportions generated from those two columns - see code below).
I have managed so far to get on one side a working upload button for my file, and on the other side, working diagrams using the CSV file after having imported it in RStudio's dataset. Unfortunately, I didn't yet find a way to get both functions working together in the same shinyapp: user upload function and then diagram display from the uploaded CSV.
The code I have worked on so far looks like this:
library(shiny)
ui <- fluidPage( sidebarLayout( sidebarPanel( fileInput("file1", "Choose CSV File", accept = c( "text/csv", "text/comma-separated-values,text/plain", ".csv") ), tags$hr(), checkboxInput("header", "Header", TRUE) ), mainPanel( tableOutput("contents"), h1("Women-Men Balance"), plotOutput("diagramsexe"), h1("Balance by discipline"), plotOutput("diagramsexedisc"), h1("Women by Discipline"), plotOutput("diagramsexedisconlyF") ) ) ) server <- function(input, output, session) { Genre <- eventReactive(input$file, { read.csv(input$file1$datapath) }) output$diagramsexe <- renderPlot({ table_sexe <- table(Genre$sexe) table_sexeprop <- prop.table(table_sexe) barplot(table_sexeprop) }) output$diagramsexedisc <- renderPlot({ table_discXsexe <- table(Genre$sexe,Genre$SISEDisc) table_discXsexe_prop <- prop.table(table_discXsexe) barplot(table_discXsexe_prop) }) output$diagramsexedisconlyF <- renderPlot({ table_discXsexeinv <- table(Genre$SISEDisc,Genre$sexe) table_discXsexe_prop_onlyF <- table_discXsexeinv[,c("F")] barplot(table_discXsexe_prop_onlyF) }) shinyApp(ui, server)
}
I would really really appreciate if you could help me.
Thank you so much in advance!