2017-12-29 4 views
0

저는 뉴욕 범죄 기록 데이터를 기반으로 반짝이는 앱을 만들려고합니다. 단일 반짝 페이지 접근 방식을 사용하고 있습니다. 데이터는 다음과 같습니다. 범죄 통계를 출력 할 연도를 선택하면 어떤 이유로 RStudio의 뷰어에서만 출력되고 Shiny 팝업의 기본 패널에서는 출력되지 않습니다. 여기에 전체 코드는 다음과 같습니다반짝이는 플롯 플롯을 올바르게 출력하는 방법은 무엇입니까?

# Shiny App exploring New York City Crime Data between 2006-2016 
# Data Source: https://data.world/data-society/nyc-crime-data 

#########################Global Data###################### 

# Data Reading 
set.seed(123) 
library("shiny") 
library("lubridate") 
library("plotly") 
nypd<-read.csv("NYPD_Complaint_Data_Historic.csv") 

#Data Massaging 
nypd$year<-year(as.Date(nypd$RPT_DT,'%m/%d/%Y')) 
nypd$month<-month(as.Date(nypd$RPT_DT,'%m/%d/%Y')) 
nypd<-nypd[nypd$OFNS_DESC != "",] 
nypd2<-nypd[,c(1,6,8,14,16,17,22,23,25,26)] 

ui<-fluidPage(
titlePanel("New York City Crime Data from 2006-2016"), 
sidebarLayout(
    sidebarPanel(
    sliderInput("year","Year of Crime",min=2006,max=2016,value=2008,step = 1) 
    ), 
    mainPanel(plotOutput("crimeplot")) 
) 
) 


server<-function(input,output){ 
    output$crimeplot<-renderPlot({ 

    nypd_yr_sorted<-nypd2[nypd2$year==input$year,] 
    agg_data<-  aggregate(nypd_yr_sorted$CMPLNT_NUM,by=list(nypd_yr_sorted$OFNS_DESC),FUN=functi  on(x)length(unique(x))) 
    colnames(agg_data)<-c("Crime","Crime count") 
    bar_data<-agg_data[order(agg_data$`Crime count`, decreasing = TRUE),][1:5,] 
    plot_ly(bar_data,x=~Crime,y=~`Crime count`,type="bar",color = ~Crime) %>% layout(xaxis= list(showticklabels = FALSE)) 
    }) 

} 

shinyApp(ui = ui, server = server) 
+0

당신이 사용하고있는 크기가 수백 MB 인 데이터 파일. 그 거대한 파일을 다운로드하지 않고도 앱을 재현 할 수 있도록 단지 몇 줄을 복사하여 붙여 넣을 수 있습니까? – Phil

+0

@ Phil - 실제로는 1.3GB이지만 친구들 중에 몇 백 메가 바이트입니까? –

+1

@ Piyush - 내 대답에 나열된 변경 사항을 적용하여 반짝이는 앱을 사용할 수 있었습니까? –

답변

1

Plotly 차트 plotlyOutput()renderPlotly()로 렌더링됩니다.

  1. 변경 mainPanel()output$crimeplot

output$crimeplot<-renderPlotly({로 변경

  • mainPanel(plotlyOutput("crimeplot"))에 ... 출력 : 코드에 두 가지 변화가 필요

    enter image description here

  • +0

    빠른 답변 주셔서 감사합니다. 그것은 효과가 있었다. 그러나 내 시각화는 당신만큼 좋지 않습니다. 귀하의 저장고는 더 넓고 색상은 생생합니다. 나는 당신이 그 (것)들을 어떻게 비틀 었다는 것을 알고 있기 위하여 아주 흥미 롭다? –

    +0

    @PiyushVerma - 원래 게시 한 코드에서 plot_ly()의 인수를 변경하지 않았습니다. 어떤 운영 체제를 사용하고 있습니까? OS X에서 차트를 실행했습니다. 일부 기본 설정은 운영 체제마다 다를 수 있습니다. –

    관련 문제