问题
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