ggvis输出没有出现在闪亮的应用程序中

时间:2015-10-05 20:51:38

标签: r shiny ggvis

我对这里的错误感到茫然,而Stack上的其他主题用户讨论他们的ggvis +闪亮的困境似乎并不适用,尽管它们非常相似。

首先,基本问题是我的ggvis可视化没有出现在Shiny应用程序中。我的Shiny应用程序中有另一个显示数据表的选项卡,工作正常。此外,当我换掉ggvis并使用ggplot2时(除了使用更改为调用可视化的ui.R中的兼容函数之外,其余代码保持不变),这也可以正常工作。我在RStudio中没有收到任何错误消息或警告。我怀疑我在bind_shiny函数中遇到了一些问题,但是我尝试过的任何东西似乎都没有用。

这是我的服务器.R代码:

library(shiny)
library(ggvis)
library(dplyr)

#import file created by screener.R

final <- read.csv("final-test.csv") 


 # Define server logic required to complete visualization

shinyServer(function(input, output) {

reactviz <- reactive({allviz <- filter(final, DivYield >= input$Yield[1])
allviz <- filter(allviz, DivYield <= input$Yield[2])
allviz <- filter(allviz, PAYOUTRATIO >= input$PayoutRatio[1])
allviz <- filter(allviz, PAYOUTRATIO <= input$PayoutRatio[2])
allviz <- filter(allviz, PriceSales >= input$PriceSales[1])
allviz <- filter(allviz, PriceSales <= input$PriceSales[2])
allviz <- filter(allviz, MarketCapinMil >= input$MarketCap[1])
allviz <- filter(allviz, MarketCapinMil <= input$MarketCap[2])
allviz <- allviz[1:35,]
})

output$visplot <- renderPlot({

allviztip <- function(x) { if(is.null(x))return(NULL) 
  row <- allviz[allviz$id == x$id,c(1,4,8,10,11,12,13)]
  paste0(names(row),":",format(row),"</div>",collapse="<br />")}

reactviz() %>% ggvis(x=~PriceBook,y=~DivYield,key:=~id,size=~MarketCapinMil,shape=~PayoutCat,fill=~PriceSales) %>%
  layer_points() %>% add_tooltip(allviztip,"click") %>% add_axis('x', title='Price/Book Ratio',title_offset=60,properties=axis_props(labels=list(fontSize=12), title=list(fontSize=18))) %>% 
  add_axis("y", title = "Dividend Yield",title_offset=50,properties=axis_props(labels=list(fontSize=12), title=list(fontSize=18))) %>% 
  add_legend(scales="shape", title="Payout Ratio Category") %>% 
  add_legend(scales="fill", title="Price/Sales Ratio", properties = legend_props(legend = list(y = 100))) %>%
  add_legend(scales="size", title="Market Cap",values=c(1,25,50,100,500,1000,5000,50000,100000,300000),properties = legend_props(legend = list(y = 200))) %>% 
  set_options(duration = 0,height="auto",width="auto") %>%
  scale_numeric(property="fill",range=c("lightblue","darkblue")) %>%
  bind_shiny("visplot","visplot_ui") 

})

output$stockdata <- renderTable({

tableviz <- filter(final, DivYield >= input$Yield[1])
tableviz <- filter(tableviz, DivYield <= input$Yield[2])
tableviz <- filter(tableviz, PAYOUTRATIO >= input$PayoutRatio[1])
tableviz <- filter(tableviz, PAYOUTRATIO <= input$PayoutRatio[2])
tableviz <- filter(tableviz, PriceSales >= input$PriceSales[1])
tableviz <- filter(tableviz, PriceSales <= input$PriceSales[2])
tableviz <- filter(tableviz, MarketCapinMil >= input$MarketCap[1])
tableviz <- filter(tableviz, MarketCapinMil <= input$MarketCap[2])
tableviz


})



})

这是我的ui.R代码:

library(shiny)
library(ggvis)

# Define UI for application that draws a histogram
shinyUI(fluidPage(

  # Application title
  titlePanel("Visual Stock Screener"),

  # Sidebar with a slider input for the number of bins
  sidebarLayout(
    sidebarPanel(
      sliderInput("MarketCap",
                  "Market Capitalization (in Tens of Millions)",
                  min = 1,
                  max = 60000,
                  value = c(100,30000)),

      sliderInput("Yield",
                  "Dividend Yield:",
                  min = 0,
                  max = 1,
                  value = c(.04,.5)),

      sliderInput("PayoutRatio",
                  "Payout Rato:",
                  min = 0,
                  max = 5,
                  value = c(0,.5)),


      sliderInput("PriceSales",
                  "Price/Sales Ratio:",
                  min = 0,
                  max = 25,
                  value = c(0,7)),


      sliderInput("PriceBook",
                  "Price/Book Ratio:",
                  min = 0,
                  max = 30,
                  value = c(0,4))

    ),

    # Show a plot of the generated distribution
    mainPanel(
      tabsetPanel(type="tab",
                  tabPanel("Plot",ggvisOutput("visplot"),uiOutput("visplot_ui")),
                  tabPanel("Data",tableOutput("stockdata")),
                  tabPanel("Documentation",includeHTML("screener-documentation.html"))
                  )


  )
)))

对于我做错了什么以及为什么我的可视化不会出现的任何想法?

0 个答案:

没有答案