3
我有下面的代码,我尝试运行失败。我只是希望能够根据输入范围过滤图形输出。在这个例子中,如果范围输入设置为1-5,我想在图上看到5个点,同样2-5的范围输入显示4个点。Shiny Reactive ggplot Output
##UI
require(shiny)
shinyUI(fluidPage(
titlePanel(title=h4("Races", align="center")
),
sidebarPanel(
sliderInput("num", "Number:",
min = 0, max = 5,step=1,value=c(0,2)),
mainPanel(
plotOutput("plot2")))))
##server
library(dplyr)
library(ggplot2)
shinyServer(function(input,output){
num<-c(1,2,3,4,5)
let<-c("A","B","C","D","E")
date<-c("2015-5-1","2015-6-1","2015-7-1","2015-8-1","2015-9-1")
df<-data.frame(num,let,date)
dat<-reactive({
df %>% filter(num==input$num)})
output$plot2<-renderPlot({
ggplot(dat(),aes(x=date,y=num))+geom_point(colour='red')},height = 400,
width = 600)})
我想显示基于所述输入范围图表上的值的范围,但只有1值被示出,与对应的日期值不在该范围。
在此先感谢。
没有,点@Pork印章,如果输入范围是1-5,我想看到5点,同样与输入范围2-5我想看到4点。我怀疑会带来的1-5范围输入:ggplot(df,aes(x = date,y = num))+ geom_point(color ='red')但是不会 – Lebeauski