0

I have a simple shiny app.

#ui.r
navbarPage(
  "Application",
  tabPanel("General",
           sidebarLayout(

             sidebarPanel(
               uiOutput("book4"),
               uiOutput("book5"),
               uiOutput("book6"),
               uiOutput("book7")

             ),
             mainPanel(
               DT::dataTableOutput("hot5")

             )
           )))
#server.r
library(shiny)
library(DT)
library(tidyverse)
server <- function(input, output,session) {

  output$book4<-renderUI({
    numericInput("bk4", "From",
                 value = 1,
                 min=1,max=input$bk5)


  })
  output$book5<-renderUI({
    numericInput("bk5", "To",
                 value = 1,
                 min=1,max=10)


  })
  output$book6<-renderUI({
    numericInput("bk6", "From",
                 value = 1,
                 min=1,max=10)


  })
  output$book7<-renderUI({
    numericInput("bk7", "To",
                 value = 1,
                 min=1,max=10)


  })
  rt2<-reactive({
    DF=data.frame(
      Id= (input$bk4:input$bk5),
      Label=paste("Item",input$bk4:input$bk5),
      Pf=as.integer(rep.int(0,as.numeric(input$bk5-input$bk4+1))),
      stringsAsFactors = FALSE
    )
  })
  output$hot5 <-DT::renderDataTable(

    rt2()%>% 
      rowid_to_column("Row") %>% 
      mutate(Row = ""),
    rownames = FALSE,
    extensions = "Select",
    options = list(
      columnDefs = list(list(className = "select-checkbox", targets = 0, orderable = FALSE)),
      select = list(style = "multi", selector = "td:first-child")
    )

  )
}

As you can see I use a pair of numericInput() (From-To) to set a range of rows that will be displayed in the datatable. Below this I have a second pair which I would like to use to choose a different range and display it at the same time in the table. For example I could choose 2nd to 6th row from the 1st pair and 8th to 10th from the 2nd. Note that the two pairs should not take as inputs the same values. For example if I choose a range 2 to 4 in first range then 2nd to 4th rows will be excluded for selection in the 2nd range.

firmo23
  • 7,490
  • 2
  • 38
  • 114
  • Your example is currently not reproducible; the formatting is a bit off and we do not have access to your data. It will be much easier to help if you provide a reproducible example, for some tips on how to do that, see [here](https://stackoverflow.com/questions/48343080/how-to-convert-a-shiny-app-consisting-of-multiple-files-into-an-easily-shareable). – Florian Jul 17 '18 at 11:49
  • Sorry but how it is not reproducible? I create the dataframe inside my server.r file – firmo23 Jul 17 '18 at 11:58
  • Sorry, my bad! I overlooked that. – Florian Jul 17 '18 at 12:00

1 Answers1

1

Why not just combine them into a single data frame like so:

rt2<-reactive({
    DF=data.frame(
      Id= unique(c(input$bk4:input$bk5,input$bk6:input$bk7)),
      Label=paste("Item",unique(c(input$bk4:input$bk5,input$bk6:input$bk7))),
      Pf=as.integer(rep.int(0,length(unique(c(input$bk4:input$bk5,input$bk6:input$bk7))))),
      stringsAsFactors = FALSE
    )
  })
jasbner
  • 2,253
  • 12
  • 24
  • That is indeed something that I was working on too. Sorry my bad, I added an edit which explains that the 2 ranges should not take common values. Because they are displayed twice. – firmo23 Jul 17 '18 at 12:26