2017-04-10 3 views
0

shinyApps.io에서 배포 할 때 몇 가지 문제에 직면하고 있습니다. 나는 R 스튜디오 IDE에서 응용 프로그램을 실행하는 경우는 전혀 괜찮지 만 shinyApps.io와 쇼에 작동하지 않을 수 있습니다 여전히 shinyApps.io 만에 이미 세 개의 파일을 게시 한shinyApps.io에서 shiny deploy

ERROR: cannot open the connection 

(UI, 서버, data.csv) 일할 수 없다.

cannot open file 'C:\Users\User\Downloads\Category_dashboard\ads_test\rawdash.csv': No such file or directory 

누군가가이 문제를 도울 수 : 나는 shinyApps.io에 로그를 확인 때 쇼, 데이터를 읽을 수 없기 때문에 생각?

UI :

# package 
library(shiny) 
library(shinydashboard) 
library(devtools) 
library(xts) 
library(dplyr) 
library(ggplot2) 
library(dplyr) 
library(DT) 
library(readxl) 
# graphic 
library(streamgraph) 
library(treemap) 
library(bubbles) 
library(googleVis) 
library(dygraphs) 
# share to server 
library(rsconnect) 
library(RJSONIO) 

# read data 
dash_path <- file.path("C:\\Users\\User\\Downloads\\Category_dashboard\\ads_test\\rawdash.csv") 
dash <- read.csv(dash_path, 
       colClasses = c("character","character","character","character","character","character","numeric","numeric")) 

# app 
ui <- dashboardPage(skin="black", 
        dashboardHeader(title = "Segment Dashboard", titleWidth = 300), 

        dashboardSidebar(selectInput("c1_input", label = "Segment", 
               choices = c(unique(dash$c1)), multiple = TRUE), 
            selectInput("c2_input", label = "Sub-segment", 
               choices = c("All", unique(dash$c2)), multiple = TRUE), 
            selectInput("c3_input", label = "Sub-sub-segment", 
               choices = c("All", unique(dash$c3)), multiple = TRUE), 
            selectInput("geo_input", label = "Country", 
               choices = c("All", unique(dash$geo)), multiple = TRUE), 
            selectInput("d1_input", label = "Device", 
               choices = c("All", unique(dash$device)), multiple = TRUE) 
            #uiOutput("c1_output"), 
            #uiOutput("c2_output"), 
            #uiOutput("c3_output"), 
            #uiOutput("geo_output"), 
            #uiOutput("d1_output") 
        ), 
        dashboardBody(fluidRow(valueBoxOutput("UserBox"), 
              valueBoxOutput("SessionBox"), 
              downloadButton("download_data", "Download")), 
            br(), 
            plotOutput("bar", height = 250, width = 925), 
            br(), 
            DT::dataTableOutput("table") 
        ) 
) 

서버

server <- function(input, output, session){ 
    # load data 
    dash_path <- file.path("C:\\Users\\User\\Downloads\\Category_dashboard\\ads_test\\rawdash.csv") 
    dash <- read.csv(dash_path, 
        colClasses = c("character","character","character","character","character","character","numeric","numeric")) 

    # total user 
    output$UserBox <- renderValueBox({valueBox(format(sum(dash$nb_user)), 
              "Total User", icon = icon("area-chart"), color = "green") 
    }) 
    # filtered user 
    output$SessionBox <- renderValueBox({valueBox(format(sum((filtered()$nb_user))), 
               "Segment User", icon = icon("shopping-cart"), color = "green") 
    }) 

    # download output 
    output$download_data <- downloadHandler(
    filename <- function(){ 
     sprintf("download.csv", Sys.Date()) 
    }, 
    content <- function(filename){ 
     dash <- filtered() 
     write.csv(dash, file = filename, row.names = FALSE) 
    } 
) 

    ## UI 
    #output$c1_output <- renderUI({ 
    #selectInput("c1_input", label = "Segment", choices = c("All" = "", unique(dash$c1)), multiple = TRUE)}) 
    #output$c2_output <- renderUI({ 
    #selectInput("c2_input", label = "Sub-segment", choices = c("All" = "", unique(filtered()$c2)), multiple = TRUE)}) 
    #output$c3_output <- renderUI({ 
    #selectInput("c3_input", label = "Sub-sub-segment", choices = c("All" = "", unique(filtered()$c3)), multiple = TRUE)}) 
    #output$geo_output <- renderUI({ 
    #selectInput("geo_input", label = "Country", choices = c("All" = "", unique(filtered()$geo)), multiple = TRUE)}) 
    #output$d1_output <- renderUI({ 
    #selectInput("d1_input", label = "Device", choices = c("All" = "", unique(filtered()$device)), multiple = TRUE)}) 
    #output$d2_output <- renderUI({ 
    #selectInput("d2_input", label = "Device Type", choices = c("All" = "", unique(filtered()$sub_device)), multiple = TRUE)}) 

    ## update selection 
    observe({ 
    c2_input <- if (is.null(input$c1_input)) character(0) else { 
     filter(dash, c1 %in% input$c1_input) %>% 
     `$`('c2') %>% 
     unique() %>% 
     sort() 
    } 
    stillSelected <- isolate(input$c2_input[input$c2_input %in% c2_input]) 
    updateSelectInput(session, "c2_input", choices = c2_input, selected = stillSelected) 
    }) 

    observe({ 
    c3_input <- if (is.null(input$c1_input)) character(0) else { 
     dash %>% 
     filter(c1 %in% input$c1_input, 
       c2 %in% input$c2_input) %>% 
     `$`('c3') %>% 
     unique() %>% 
     sort() 
    } 
    stillSelected <- isolate(input$c3_input[input$c3_input %in% c3_input]) 
    updateSelectInput(session, "c3_input", choices = c3_input, selected = stillSelected) 
    }) 

    observe({ 
    geo_input <- if (is.null(input$c1_input)) character(0) else { 
     dash %>% 
     filter(c1 %in% input$c1_input, 
       c2 %in% input$c2_input, 
       c3 %in% input$c3_input) %>% 
     `$`('geo') %>% 
     unique() %>% 
     sort() 
    } 
    stillSelected <- isolate(input$geo_input[input$geo_input %in% geo_input]) 
    updateSelectInput(session, "geo_input", choices = geo_input, selected = stillSelected) 
    }) 

    observe({ 
    d1_input <- if (is.null(input$d1_input)) character(0) else { 
     dash %>% 
     filter(c1 %in% input$c1_input, 
       c2 %in% input$c2_input, 
       c3 %in% input$c3_input, 
       deo %in% input$deo_input) %>% 
     `$`('device') %>% 
     unique() %>% 
     sort() 
    } 
    stillSelected <- isolate(input$d1_input[input$d1_input %in% d1_input]) 
    updateSelectInput(session, "d1_input", choices = d1_input, selected = stillSelected) 
    }) 

    ## data for filtered user and download 
    filtered <- reactive({ 
    subset(dash, c1 == input$c1_input) 
    }) 

    ## plot 
    output$bar <- renderPlot({ 
    p <- ggplot(filtered()) + 
     geom_bar(aes(x = c1, y = nb_user, fill = c1), position="dodge", stat= "identity") + 
     theme(legend.position="top", legend.title=element_blank()) + 
     theme(axis.ticks = element_blank(), axis.title.x = element_blank(), axis.line = element_blank()) + 
     theme(axis.text.x= element_text(face= "bold", size= 10), axis.text.y= element_text(face= "bold", size= 10)) + 
     theme(strip.background = element_blank(), strip.text = element_blank()) + 
     labs(x= "", y= "", title= "") 
    print(p) 
    }) 


    ## table 
    #output$table <- renderUI({ 
    output$table <- DT::renderDataTable({ 
    filtered <- dash %>% 
     filter(c1 %in% input$c1_input, 
      c2 %in% input$c2_input, 
      c3 %in% input$c3_input, 
      geo %in% input$geo_input) 
    DT::datatable(filtered, escape = FALSE) 
    }) 

    #if (input$c1_input != "All") { 
    # dash <- dash[dash$c1 == input$c1_input,] 
    # } 
    #if (input$c2_input != "All") { 
    # dash <- dash[dash$c2 == input$c2_input,] 
    # } 
    #if (input$c3_input != "All") { 
    # dash <- dash[dash$c3 == input$c3_input,] 
    # } 
    #dash 
    #}) 
} 

답변

0

문제는 로컬 컴퓨터에있는대로, 파일 위치를 참조하고 있다는 사실이다. 이 파일 경로는 서버에 없습니다. 해결책은 파일 위치의 상대 경로로 작업하는 것입니다.

+0

shinyApps.io에서 데이터를 읽는 방법을 수정하는 방법을 보여줄 수 있습니까? 정말 고맙습니다. –

+1

csv 파일을 업로드 할 수 있다면 다음과 같이 할 수 있습니다. dash_path <- file.path (paste0 (getwd(), "/ rawdash.csv") – WHoekstra

1

파일 경로가 shinyapps.io 서버에없는 경로로 설정되어있어 앱이 작동하지 않습니다. 포함하고있는 파일의 위치에 대한 작업 디렉토리의 하위 디렉토리를 만듭니다. 작업 디렉토리가 무엇인지 확실하지 않으면 getwd()을 사용하십시오. 해당 디렉토리에 파일을 넣으십시오. 이 예에서는 'directoryname'이라는 이름을 사용 하겠지만 원하는 이름은 사용하십시오. 경로를 다음과 같이 변경하십시오 : dash_path <- file.path("directoryname\rawdash.csv") 또한 효과가있을 수 있지만 빛나는 출력 안에 함수를 작성하는 것은 일반적으로 효율성과 가용성 측면에서 바람직하지 않습니다. 예를 들어 모든 세션에서 기능을 사용할 수있게하려면 반짝이는 server() 호출 외부에서 실행해야합니다.

+0

Hi Phi, 답변 해 주셔서 감사합니다. 나는 모든 세션에서 사용할 수있는 기능에 대한 당신의 의미를 이해하지 못하고 있습니다. "예를 보여줄 수 있습니까? –