首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >主窗格中不显示ggvis可视化。

主窗格中不显示ggvis可视化。
EN

Stack Overflow用户
提问于 2017-11-30 02:59:38
回答 1查看 100关注 0票数 0

我刚开始发光,这一次给了我很大的困难。我尝试了几个建议,直到最后一次反应,但都没有效果。我不知道我做错了什么。

我尝试了%>% bind_shiny()和vis ({}),这两种方法都不起作用。如有任何建议,将不胜感激。

出现ui.R,但可视化没有,我也没有收到错误消息

server.R

代码语言:javascript
复制
library(shiny)
library(ggvis)
library(dplyr)


dataS <-read.csv("https://raw.githubusercontent.com/indianspice/IS608/master/Final%20Project/Data/shinydata.csv",
              stringsAsFactors = FALSE)


function(input, output, session) {
#Filter breaches
breaches <- reactive({
    records <- input$records
    minyear <- input$year[1]
    maxyear <- input$year[2]

    # Apply filters
    b <- dataS %>%
    filter(
    TotalRecords >= records,
    Year >= minyear,
    Year <= maxyear
) %>%
arrange(records)

#Filter by breach
if (input$breach != "All") {
    breach <- paste0("%", input$breach, "%")
    b <- b %>% filter(Breach %like% breach)
}

#Filter by company
if (!is.null(input$company) && input$company != "") {
    company<- paste0("%", input$director, "%")
    b <- b %>% filter(Company %like% company)
}     

reactive({
    xvar_name <- names(axis_vars)[axis_vars == input$year]
    yvar_name <- names(axis_vars)[axis_vars == input$records]

    xvar <- prop("x", as.symbol(input$xvar))
    yvar <- prop("y", as.symbol(input$yvar))

    breaches %>%
        ggvis(x=xvar, y=yvar, stroke = ~breach) %>%
        layer_points() %>%
        add_axis("x", title = xvar_name) %>%
        add_axis("y", title = yvar_name) %>%
        add_legend("stroke", title = "Breach Type", 
                   values = c("Hacking or Malware", 
                              "Unintended Disclosure",
                              "Insider",
                              "Portable Device",
                              "Stationary Device",
                              "Unknown",
                              "Payment Card Fraud",
                              "Physical Loss")) %>%
        scale_nominal("stroke", domain = c("Hacking", 
                                           "Unintended",
                                           "Insider",
                                           "Portable",
                                           "Stationary",
                                           "Unknown",
                                           "Payment",
                                           "Physical"),
                          range = c("red", "orange"))  %>%
        bind_shiny("ggvis", "ggvis_ui")
   }) 

})


}

ui.R

代码语言:javascript
复制
library(shiny)
library(ggvis)

dataS <- read.csv("https://raw.githubusercontent.com/indianspice/IS608/master/Final%20Project/Data/shinydata.csv",
             stringsAsFactors = FALSE)


fluidPage(
    titlePanel("Data Breaches in the United States"),
    #fluidRow(
       column(4,
               h4("Filter Data"),
               sliderInput("records", "Number of records breached",
                           min = 10,
                           max = 1000000,
                           value = 10000,
                           step = 500),
               sliderInput("year", "Year breach reported",
                           sep = "",
                           min = 2005, 
                           max = 2017, 
                           value = c(2007, 2010)),
               selectInput("breach", "Type of breach",
                           c("All", 
                             "Hacking or Malware", 
                             "Unintended Disclosure", 
                             "Insider", 
                             "Portable Device", 
                             "Stationary Device",
                             "Unknown", 
                             "Payment Card Fraud", 
                             "Physical Loss")),
               selectInput("organzation", "Select type of organization",
                           choices = unique(dataS$TypeofOrganization)),
               selectInput("company", "Select company",
                           choices = unique(dataS$Company)
               ),
              textInput("companyName", "Enter company name")
           ),

    #),
    mainPanel(
        uiOutput("ggvis_ui"),
        ggvisOutput("ggvis")
    )


    )

数据

代码语言:javascript
复制
Company TypeofBreach            TypeofOrganization     TotalRecords Year
Bullitt Unintended Disclosure   Educational Institutions    676     2009
Roane   Portable Device         Educational Institutions    14783   2009
Halifax Portable Device         Healthcare Medical Provider 33000   2009
Suffolk Unintended Disclosure   Educational Institutions     300    2009
Penrose Physical Loss           Healthcare Medical Providers  175   2009
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-30 22:38:07

您是在一个反应性内部定义一个反应性,这是不好的。您应该使用breaches定义您的反应性(更改)数据reactive --这很好。然后,您应该使用来观察该数据的变化。

代码语言:javascript
复制
observe({
   breaches() ... <do something>
   ...
   %>% bind_shiny("ggvis", "ggvis_ui")
})

最后,使用bind_shiny。关于如何做它的介绍,请参阅下面的最小示例(受ggvis帮助页的启发):

代码语言:javascript
复制
library(shiny)
runApp(list(
  ui = fluidPage(
    sliderInput("slider", "Select rows from mtcars to consider", min=1, max = nrow(mtcars), step = 1, value = c(1,10)),
    ggvisOutput("p"),
    uiOutput("p_ui")
  ),
  server = function(input, output) {

    # define the data according to some input
    data <- reactive({
      mtcars[ input$slider[1] : input$slider[2], ]
    })

    # observe changes in the data and update ggvis plot accordingly
    observe({
     data %>%
        ggvis(~wt, ~mpg) %>%
        layer_points() %>%
        bind_shiny("p", "p_ui")
    })
  }
))

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47565211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档