Does anyone know why it does not report the result on this Shiny

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)

Your code as written will cause table1 (which may contain a file you loaded) to be overwritte by manipulations of df that you have preloaded

This is also impossible as it wants to use input$Revista which is not a define ui input

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.