I have these codes from Shiny, but I don't know why when I press the calculate button, it fails to report the result. I hope that when I upload the csv file with magazine names, it will give as a result which quartile it belongs to.
I would appreciate any help, I am stuck in this part of the process.
library(dplyr)
library(shiny)
df <- data.frame(Revista=c("Ca-A Cancer Journal for Clinicians",
"Nature Reviews Molecular Cell Biology",
"Quarterly Journal of Economics"),
Cuartil=c("Q1", "Q2", "Q3"))
txt <- c("Revista", "Nature Reviews Molecular Cell Biology", "Quarterly Journal of Economics")
writeLines(txt, "outfile.csv")
ui <- fluidPage(sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File", accept = ".csv"),
checkboxInput("header", "Header", TRUE),
br(),
actionButton("button1", "Calcule")
),
mainPanel(tableOutput("contents"))
))
server <- function(input, output) {
rv = reactiveValues()
mydf <- reactive({
file <- input$file1
ext <- tools::file_ext(file$datapath)
req(file)
#validate(need(ext == "csv", "Please upload a csv file"))
read.csv(file$datapath, header = input$header)
})
observeEvent(input$file1, {
rv$table1 = mydf()
})
observeEvent(input$button1, {
rv$table1 = df %>% filter(Revista %in% input$Revista) %>%
distinct(Revista, Cuartil) %>%
group_by(Cuartil) %>%
slice(which(Revista == input$Revista))
})
output$contents <- renderTable({
rv$table1
})
}
shinyApp(ui = ui, server = server)