2017-11-30 20 views
0

나는 반짝 반짝 빛나는 새롭지 만 나에게 그렇게 어려운 일을주고 있습니다. 나는 마지막 반응이 있었지만 아무도 작동하지 않는 것을 발견 한 몇 가지 제안을 시도했다. 내가 뭘 잘못하고 있는지 모르겠다.ggvis 시각화가 메인 창에 나타나지 않습니다.

반응 형 ({})과 vis %> % bind_shiny()가 작동하지 않았던 Vis (<)를 시도했습니다. 어떤 제안이라도 대단히 감사하겠습니다.

ui.R가 나타납니다하지만 시각화하지 않습니다 나는 오류 메시지

server.R

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

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") 
    ) 


    ) 

데이터

을하지 않습니다
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 

답변

1

당신은 반응성 내부의 반응성 물질을 정제하는 것은 나쁘다. 반응 형 (변경) 데이터 breachesreactive을 사용하여 정의해야합니다. 괜찮습니다.

observe({ 
    breaches() ... <do something> 
    ... 
    %>% bind_shiny("ggvis", "ggvis_ui") 
}) 

후, 마지막에, bind_shiny를 사용 : 그런 다음 observe를 사용하여 해당 데이터의 변화를 관찰한다. (ggvis help pages에서 영감)을 수행하는 방법에 대한 소개를 위해 다음과 같은 최소한의 예를 참조하십시오

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") 
    }) 
    } 
)) 

enter image description here