Getting error in UI for column no greater than required

I am reading an excel in shiny. What I need is if the column length is greater or lesser than specified no. then it should give an error message in the UI.

Can someone help me with this? How to achieve this requirement.

Hi, there are multiple ways to do this depending on the events in your Shiny app.
In general, it can be something like this inside an observer:

mydf <-read.xlsx(inFile$datapath, 1)
if(ncol(mydf) != 10){
showNotification("please select a file with 10 columns", type="warning")
} else{
output$mytable = renderTable({ mydf })
}

Hi, can you test this example and let me know if you have any issues with it?
you can also provide some examples of your code if it's very different than this one.

library(shiny)
library(readxl)

ui <- fluidPage(
  fileInput("file1","Select the file"),
  tableOutput("mytable")
)

server <- function(input, output, session) {
  
  observeEvent(input$file1,{
   print(input$file1$datapath)
    mydf <- read_excel(input$file1$datapath, 1)
    if(ncol(mydf) != 10){
      showNotification("please select a file with 10 columns", type="warning")
    } else{
      output$mytable = renderTable({ mydf })
    }
  })
}

shinyApp(ui, server)


Hi, we tried to show the notification but the application closes without prompting anything in the UI. Thats the problem I am facing.