问题
If you run the script below, You get a data table representing iris data and a range slider which gives you values greater than and equal to the chosen point on the prior circle of your selection in the slider. I want a logic such that when left slider node is kept at say 5 and right slider at 7, I want the data to be displayed "= and above 5" and "< and equal to 7".These values however should be dynamic. Also for the two circles on the sliders, is there a way to give triangle widgets which are small in size. Attaching the snapshot for reference. Thanks and please help.
#App
library(shiny)
library(shinydashboard)
library(dplyr)
library(scales)
library(DT)
#Declaring the UI
ui <- fluidPage(
titlePanel("Slider Test"),
fluidRow(
column(4,
sliderInput("range", "Select the Name Similarity %",
min = 4, max = 8,
value = c(min,max) ))
),
# Create a new row for the table.
fluidRow(
DT::dataTableOutput("table")
)
)
#Declaring the Server
server <- function(input, output) {
output$table <- DT::renderDataTable(DT::datatable({
Prod_total1 <- subset(iris, as.numeric(sub("%", "",
iris$Sepal.Length)) >= input$range)
Prod_total1
}))
}
shinyApp(ui, server)
回答1:
in order to access sliderInput
values in the range mode please use input$range[1]
to access the first extreme and input$range[2]
to access the second
#App
library(shiny)
library(shinydashboard)
library(dplyr)
library(scales)
library(DT)
#Declaring the UI
ui <- fluidPage(
titlePanel("Slider Test"),
fluidRow(
column(4,
sliderInput("range", "Select the Name Similarity %",
min = 4, max = 8,
value = c(min,max) ))
),
# Create a new row for the table.
fluidRow(
DT::dataTableOutput("table")
)
)
#Declaring the Server
server <- function(input, output) {
output$table <- DT::renderDataTable(DT::datatable({
iris[iris$Sepal.Length >= input$range[1] & iris$Sepal.Length <= input$range[2],]
}))
}
shinyApp(ui, server)
来源:https://stackoverflow.com/questions/47713721/handling-and-optimizing-a-range-slider-in-r