0

I want to use the validate function in Rshiny.

  output$one <- renderTable({
  isolate({
  Loadprob <- input$prob1
  prob <- read.xls(Loadprob$datapath)

  validate(need(ncol(prob)==13, "Error"))

But the function validate does not returns the "Error" message and I don't know why.

Thank you!

  • `prob` depends on `Loadprob$datapath` so it should be a reactive. Try `prob<-reacitve(read.xls(Loadprob$datapath))` and the change `prob` to `prob()` in the `need` statement. – John Paul Nov 21 '16 at 16:25
  • Still not working, I get the error : Warning: Error in [: object of type 'closure' is not subsettable. –  Nov 22 '16 at 14:02
  • Check if this helps http://stackoverflow.com/questions/40623749/what-is-object-of-type-closure-is-not-subsettable-error-in-shiny If not, please post your updated code. – John Paul Nov 22 '16 at 14:06

1 Answers1

1

I created a reproducible example of your code. Please for further questions, try to do it yourself. This makes it a lot easier to find and solve the problem.

library(shiny)
ui <- fluidPage(
  sidebarLayout(    
    sidebarPanel(
      fileInput("prob1", label = "Excel File", multiple = F)
    ),
    mainPanel(
      tableOutput("one")
    )
  )
)
# Server logic
server <- function(input, output) {
  output$one <- renderTable({
      req(input$prob1)
      Loadprob <- input$prob1

      prob <- read.csv(Loadprob$datapath, header = T, sep = ";")
      ## prob <- read.xls(Loadprob$datapath)

      validate(need(ncol(prob)==13, "Error"))
      prob
  })
}
shinyApp(ui, server)

I used read.csv instead of read.xls, as i could not install the xlsx-package, but that shouldnt be the issue.

You also have to include a req() at the beginning of the renderTable function, as it should only be executed, when a file is uploaded.

At the end, you have to tell which variable should be plotted as a table, which in this case is "prob".

SeGa
  • 9,454
  • 3
  • 31
  • 70