2014-02-21 1 views
0

Shiny App을 만들려고합니다.Rstudio Shiny - Websource에서 data.frame 업데이트

웹에서 CSV 파일을 다운로드하고 로컬 컴퓨터에 저장 한 다음 분석을 수행하고 싶습니다.

내 현재의 접근 방식은 다음과 같습니다

ui.R

library(shiny) 

shinyUI(pageWithSidebar(

    # Application title 
    headerPanel("TEST"), 

    sidebarPanel(
    sliderInput("range", "Date Range:", 
       min = 0, max = 15, value = c(0,15)) 
), 

    # Show a tabset that includes a plot, summary, and table view 
    # of the generated distribution 
    mainPanel(
    tabsetPanel(
     tabPanel("Plot", plotOutput("plot")) 
) 
)) 

server.R

library(shiny) 

shinyServer(function(input, output) { 

datasetInput <- function(){ 

    x1 <- strptime(Sys.time(), "%Y-%m-%d %H:%M:%S") 
    x2 <- strptime(file.info("/srv/shiny-server/Data/current.csv")$mtime, "%Y-%m-%d %H:%M:%S") 

if (difftime(x1, x2, units='mins') > 20){ 
    str <- "wget http://www.web.com/file.csv -O /srv/shiny-server/Data/current.csv" 
    system(str) 
} 
    data <- read.csv("/srv/shiny-server/Data/current.csv") 
    return(data) 
} 

output$plot <- renderPlot({ 

data <- datasetInput() 
plot(data) 

}) 

그래서 모든 것이 작동합니다. 데이터는 완벽하게 그려집니다. 문제는 wget 스크립트가 호출되지 않는다는 것입니다. 내가 어디에 넣든 상관없이.

내 단순한 목표는 앱 실행시 CSV 파일을 다운로드하고 저장하는 것입니다. 그런 다음 해당 CSV 파일을 주요 데이터 프레임으로 읽습니다.

궁극적 인 목표는 내 앱이 누군가 앱을 수행 할 때마다 시간 확인 (파일이 20 분이 경과했는지 확인)입니다. 이전 버전 인 경우 파일을 다운로드/저장하고 데이터 프레임을 업데이트하려고합니다.

* note * wget 함수를 사용하면 암호로 보호 된 CSV 파일에 액세스 할 때 발생하는 문제를 해결할 수 있습니다.

문제/솔루션은 여기에 설명되어 있습니다 : R Import - CSV file from password protected URL - in .BAT file

내가 어떻게 빛나는 작품에 대해 잘 모르는, 반짝 응용 프로그램을 생성하는 데 사용되는 코드에서 대부분입니다 : http://rstudio.github.io/shiny/tutorial/#tabsets

답변