闪亮的反应曲线图输出 [英] Shiny Reactive ggplot Output

查看:18
本文介绍了闪亮的反应曲线图输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试运行以下代码,但未成功。我只想能够过滤一个图形输出的基础上输入范围。在本例中,如果范围输入设置为1-5,我希望在图形上看到5个点,同样,范围输入2-5显示4个点。

##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个值,而不是具有相应日期的值范围。

提前感谢。

推荐答案

这是您想要的吗?编辑:现在您可以看到您指定的所有点

#rm(list = ls())
library(shiny)
library(ggplot2)

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)

ui <- fluidPage(
  titlePanel(title=h4("Races", align="center")),
  sidebarPanel( 
    sliderInput("num", "Number:",min = 0, max = 5,step=1,value=c(1,2))),
  mainPanel(plotOutput("plot2")))

server <- function(input,output){

  dat <- reactive({
    test <- df[df$num %in% seq(from=min(input$num),to=max(input$num),by=1),]
    print(test)
    test
  })

  output$plot2<-renderPlot({
    ggplot(dat(),aes(x=date,y=num))+geom_point(colour='red')},height = 400,width = 600)}
shinyApp(ui, server)

这篇关于闪亮的反应曲线图输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆