Handling and optimizing a range slider in R

馋奶兔 提交于 2019-12-25 00:33:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!