Hi All,
I am an intermediate R user, completely new to shiny and web development.
I wanted to create a simple ap that highlights a particular point on a plot based on a slider value. I'd like the highlighted point to SMOOTHLY vary as you change the slider.
My first attempt is here:
https://guptavis.shinyapps.io/choppyslider/
The app is "choppy," i.e. there seems to be a noticeable lag after you release the slider for shiny to re-render the plot. I wanted something with smoother handling that updates AS you move the slider, like this:
http://bl.ocks.org/pranitar/01305d9ad0eba73dbf80
Any suggestions, please? I'm happy to move to ggvis or another graphing application if it would fix the problem?
Code:
server.R
library(tidyverse)
library(ggplot2)
library(shiny)
#Defined outside reactive elements for efficiency
x_grid <- seq(from=-2.2, to=2.2, length.out=100)
base_plot <- tibble(x = x_grid,
pdf = pnorm(x_grid)) %>%
ggplot(aes(x,pdf)) +
geom_point() + geom_line()
# Use slider to highlight particular poitn on plot
shinyServer(function(input, output) {
output$distPlot <- renderPlot({
x_val = input$x
base_plot + geom_point(x=x_val, y=pnorm(x_val),
color="pink", size=10) +
geom_vline(xintercept = x_val, color="blue")
})
})
ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("Choppy Re-Rendering"),
sidebarLayout(
sidebarPanel(
sliderInput("x",
"X-Value",
min = -2,
max = 2,
value = .1,
step = .1)
),
mainPanel(
plotOutput("distPlot")
)
)
))