sliderInput max and min values.....

36 views
Skip to first unread message

imperial...@gmail.com

unread,
Jul 21, 2016, 4:30:04 PM7/21/16
to Shiny - Web Framework for R

I need to adjust a histogram output in shiny with a range values:

#ui.R
sliderInput(inputId="adjust", label="Choose adjacency threshold", value=c(0.001, 0.9), min=0.0001, max=1),
plotOutput("hist")

#server.R
df<-reactive({
idx = m > min(input$adjust) & m < max(input$adjust)
    data.frame(
      id = row(m)[idx],
      value = m[idx])
})
output$hist<-renderPlot({hist(df()$values)})

However this doesn't seem to affect the histogram- it re-renders when I toggle the slider but its the same each time.... it takes a very long time and it just seems to take all of the values in into account?

Does anyone know how to make this work?

when I try to print the slider's min/max value- nothing comes to the page:

#ui.R
verbatimTextOutput("x")
#server
output$x<-renderPrint({min(input$adjust)})

Hence I might be approaching this the completely wrong way... does anyone know how to do this?

Timothy Adams

unread,
Jul 21, 2016, 4:58:10 PM7/21/16
to Shiny - Web Framework for R
Can you post a minimal reproducible example? I gave you a bit of a start down below, but "m" isn't defined, and df()$values doesn't seem to be defined.

ui <- fluidPage(
  sliderInput(inputId="adjust", label="Choose adjacency threshold", value=c(0.001, 0.9), min=0.0001, max=1),
  plotOutput("hist")
)


server <- function(input, output, session) {
  df <- reactive({
    idx <- m > min(input$adjust) & m < max(input$adjust)
    data.frame(
      id = row(m)[idx],
      value = m[idx])
  })
  output$hist<-renderPlot({hist(df()$values)})
}

shinyApp(ui = ui, server = server)

imperial...@gmail.com

unread,
Jul 21, 2016, 6:09:15 PM7/21/16
to Shiny - Web Framework for R
Hi timothy thanks for the reply.
m is the actually any arbitrary matrix. you can just make one with m<-cbind(c(1,2,3),c(2,3,4), c(4,5,6))


Timothy Adams

unread,
Jul 22, 2016, 11:35:25 AM7/22/16
to Shiny - Web Framework for R
It's not clear to me what you're trying to do with your matrix. Do you want to sum the values in each row of the matrix, and display the result on the histogram? 

As for the verbatimtextouput/slider - it works fine in the example below. Is this different from what you had?

ui <- fluidPage(

  sliderInput
(inputId="adjust", label="Choose adjacency threshold", value=c(0.001, 0.9), min=0.0001, max=1),

  plotOutput
("hist"),
  verbatimTextOutput
("x")

)




server
<- function(input, output, session) {

  m
<-cbind(c(0.05,0.01,3),c(2,3,4), c(4,5,6))
 
  df
<- reactive({
    idx
<- m > min(input$adjust) & m < max(input$adjust)

   
    data
.frame(
      id
= row(m)[idx],
      value
= m[idx])
 
})

  output$hist
<-renderPlot({hist(df()$value)})
 
  output$x
<-renderPrint({min(input$adjust)})
Reply all
Reply to author
Forward
0 new messages