I am learning the Shiny
interface for R
and working through the first example.
The histogram changes based on the slider input. How do I have it update continuously, while the slider is moving? Right now, it only updates when the slider stops moving.
ui.R
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("Hello Shiny!"),
# Sidebar with a slider input for the number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
))
server.R
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
# Expression that generates a histogram. The expression is
# wrapped in a call to renderPlot to indicate that:
#
# 1) It is "reactive" and therefore should re-execute automatically
# when inputs change
# 2) Its output type is a plot
output$distPlot <- renderPlot({
x <- faithful[, 2] # Old Faithful Geyser data
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})
What I have tried:
#server.R
library(shiny)
shinyServer(function(input,output) {
x<-faithful[,2]
bins <- reactive({
seq(min(x),max(x),length.out=input$bins+1)
})
output$distPlot <- renderPlot({
hist(x,breaks=bins(),col='darkgray',border='white')})
})
Is there a way to make it react faster/real-time?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…