问题
I have randomly generated a reproducible example of range
. And I wish that my input will store in the Global Environment (selectednumbers
). So when I run the shinyApp
, let's say I choose the slidebarInput
between 1
and 100
, the verbatimTextOutput
will shows (which I satisfied):
[1] 1 2 3 6 8 11 15 17 20 21 22 27
But when I checked for the selectednumbers
(Global Environment), it shows (which I don't want):
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
[21] 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
[41] 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
[61] 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
[81] 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
And this is my desired outcome for the Global Environment :
[1] 1 2 3 6 8 11 15 17 20 21 22 27
Which part I have do the mistake? Can anyone help me? Will appreciate it a lot...
This is my code :
library(shiny)
range <- c( 1 , 2 , 3 , 6 , 8 , 11 , 15 , 17 , 20 , 21 , 22 , 27 )
ui <- fluidPage(
fluidRow(
column(12,
sliderInput("slider","Slider Range",
min = 1,
max = 100,
value = c(40, 60)))),
fluidRow(
column(12, verbatimTextOutput("range"))))
server <- function(input, output) {
selected_values <- reactive({
range[range >= input$slider[1] & range <= input$slider[2]]})
output$range <- renderPrint(selected_values())
observe(selectednumbers <<- input$slider[1]:input$slider[2])
}
shinyApp(ui,server)
来源:https://stackoverflow.com/questions/61181894/how-to-read-the-only-valid-observations-in-the-rage-sliderinput-in-shiny-in-r