Error when assigning data to new column in ShinyApp datatable: replacement has 0 rows

Everything works until I try to assign pmin to a new column; at which point I get the error "replacement has 0 rows, data has 70." If I take out the line where I marked "#here", I would get two tabs of interactive ShinyApp tables. What do I do? Is this a ShinyApp problem or dataframe or did I do anything that I should not have done?

   ui <- fluidPage(
      navbarPage("Limits",
                 tabPanel("Berlin",
                          sidebarPanel(
                            
                            # Layout
                            width = 3,
                            
                            # Input: Simple integer interval ----
                            numericInput("a_b", "A.ratio1:",0.05)
                            
                          ), # sidebarPanel
                          mainPanel(
                            width = 9,
                            
                            # Output: Table summarizing the values entered ----
                            tabPanel("Berlin", tableOutput("data_Berlin"))
                            
                          ) # mainPanel
                 ), # Berlin, tabPanel
                 
                 tabPanel("China",
                          sidebarPanel(
                            
                            # Layout
                            width = 3,
                            
                            # Input: Simple integer interval ----
                            numericInput("a_c", "A.ratio1:",0.05)
    
                            
                          ), # sidebarPanel
                          mainPanel(
                            width = 9,
                            
                            # Output: Table summarizing the values entered ----
                            tabPanel("China", tableOutput("data_China"))
                            
                          ) # mainPanel
                 ) # China, tabPanel
                 
      ) # navbarPage
      
    ) # fluid page
    
    server <- function(input, output) {
      output$data_Berlin <- renderTable({
        # Process
        berlin_table$MAX <- berlin_table$avg*input$a_b
        berlin_table
      }, bordered=TRUE, digits=5)
      
      output$data_China <- renderTable({
        # Process
        china_table$MIN <- pmin(china_table$lim,input$a_c)  #here
    
        china_table
      }, bordered=TRUE, digits=5)
    }
    
    shinyApp(ui, server)

It's a problem with your dataframe. My advice is to test your "#here" line outside your shiny app and check the output of the pmin function.
I don't have access to your data, but I can get a similar error using code below, this might give you an idea what could be wrong.
mtcars$test <- pmin(NULL, mtcars$cyl)

1 Like

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.