2016-09-14 7 views
1

アクションボタンをクリックすると、Googleシートのダウンロードと日付がコンソールに表示されますが、renderPrintのファイル時間は更新されません。上記のコードと一緒にobserveEventでRenderPrintが更新されない

library(httr) 
set_config(config(ssl_verifypeer = 0L)) 
library(googlesheets) 
suppressMessages(library(dplyr)) 
library(shiny) 
library(shinydashboard) 
library(shinyjs) 

ui <- dashboardPage(
    dashboardHeader(title = "Basic dashboard"), 
    dashboardSidebar(), 
    dashboardBody(
    fluidRow(
     #One action button to download data from google spreadsheet 
     actionButton("refreshbutton", label = "Refresh"), 
     #two textoutput to show date of downloaded file 
     textOutput("refreshdate") 

    ) 
    ) 
) 
) 

server <- function(input, output) { 

observeEvent(input$refreshbutton, { 
    #On click download data from google spreadsheet 
    pulldata <- gs_key("19bPhlp7MjDZFNJcDUmHGJDxkh2h2U5j05S0c18HfBgE") %>% 
    gs_read_csv(ws="vs working", col_names=TRUE) 
    #Write data in csv 
    write.csv(pulldata, file = "attrition.csv") 
    data <- read.csv(file="attrition.csv", header = TRUE) 
    #capture modified time from csv 
    filetime <- file.mtime("attrition.csv") 
    print(filetime) 
    #inform on completion after refresh 
}) 

#print filetime in refreshdate1 
output$refreshdate <- renderPrint({ 
    filetime # <- This is not updating??? 
}) 
} 


shinyApp(ui, server) 

のGoogleスプレッドシートをダウンロードしているとき、私は、サイトが更新を示す灰色のモードに行く必要があると仮定 - このことも起きていませんか?つまり、新しいデータが完成するまで何とか処理が進行しているはずです。

答えて

1

filetime変数の範囲がobserveEventの範囲内にあるためです。変数のスコープの外側にobserveEventを使用して代入することはできません。eventReactiveを使用してください。

ちょうどそれをチェックしたところ、gs_keyはRコンソールであっても私のためにエラーを投げています。そうでなければ、これはあなたが反応性に関して探していた解決策です。

server <- function(input, output) { 
    observeEvent(input$refreshbutton, { 
    #On click download data from google spreadsheet 
    pulldata <- gs_key("19bPhlp7MjDZFNJcDUmHGJDxkh2h2U5j05S0c18HfBgE") %>% 
     gs_read_csv(ws="vs working", col_names=TRUE) 
    #Write data in csv 
    write.csv(pulldata, file = "attrition.csv") 
    #read.csv(file="attrition.csv", header = TRUE) 
    }) 

    filetime <- eventReactive(input$refreshbutton, { 
    file.mtime("attrition.csv") 
    }) 

    #print filetime in refreshdate1 
    output$refreshdate <- renderPrint({ 
    filetime() 
    }) 
} 

エラーメッセージ:

Expected content-type: 
application/atom+xml; charset=UTF-8 
Actual content-type: 
text/html; charset=UTF-8 
+0

パーフェクト。ありがとう – Vasim

+0

しかし出力はちょうど日付ではない、それはダウンロード....などの他のものがありますか?どのように私はこれを分割することができますか? – Vasim

+0

あなたは正しいです、申し訳ありません。私は新鮮なもの以外何も気にしなかった。 – GyD

関連する問題