How to read the only valid observations in the range of sliderInput in Shiny in R

随声附和 提交于 2020-04-30 09:06:06

问题


I have a list (in .csv file) from 1 to 100, but with difference between the every term is not the same.

For example, 1, 2, 4, 7, 8, 11, 13, 17, 18, 19,..., 95, 99, 100.

After that, the range I selected will store in the selected_value (Global Environment).

And here is my code :

library(shiny)
ui <- fluidPage(
  fluidRow(
    column(4,
           sliderInput("slider","Slider Range", 
                       min = 0, max = 100, value = c(40, 60)))),

  fluidRow(
    column(4, verbatimTextOutput("range"))))

server <- function(input, output) {

  output$range <- renderPrint({input$slider})
  observe(selected_value <<- input$slider)}

shinyApp(ui,server)

My problem is let's say I selected the range of 3 to 20 in the slider, and I wish the selected_value

will tell me the only valid observations : 4,7,8,11,13,17,19.

Which part of my code should modify? Will be thanks a lot to anyone who willing to help me ...


回答1:


I'm not sure I'm fully understanding what you're looking for, but this app will return the values in the range selected:

library(shiny)

range <- 0:100

ui <- fluidPage(
  fluidRow(
    column(4,
           sliderInput("slider","Slider Range", 
                       min = min(range), max = max(range), value = c(40, 60)))),

  fluidRow(
    column(4, verbatimTextOutput("range"))))

server <- function(input, output) {

  selected_values <- reactive({
    range[range >= input$slider[1] & range <= input$slider[2]] 
    })

  output$range <- renderPrint(selected_values())
}

shinyApp(ui,server)


来源:https://stackoverflow.com/questions/60944401/how-to-read-the-only-valid-observations-in-the-range-of-sliderinput-in-shiny-in

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