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.