2016-07-07 1 views
0

나는 반짝이는 테이블에 날짜를 표시하려고 노력 중입니다. 나는 약간의 연구를했고 과거에 xtable이 Shiny와 잘 작동하지 않는다는 것을 알았다. 그래서이 문제를 다루는 몇 가지 질문이 있습니다. 일상적으로 참조하는 것은 여기 R: xtable and dates에서 찾을 수 있습니다.반짝이는 테이블로 작업 할 때 날짜를 어떻게 표시합니까?

내 문제는 1) 나는 반짝이로 프로그래밍하고 xtable을 사용하여 매우 새로운 기술을 익혔습니다. 2) POSIXct 사용에 익숙하지 않습니다. 3) 위의 링크에서 제공된 솔루션을 이해하지 못합니다.

아래의 기본 코드는 도움의 손길을주십시오. 아이디어는 누군가가 데이터를 매일 입력하기 위해이 앱을 사용한다는 것입니다. 이 데이터는 .csv에 저장됩니다. .csv에 저장된 경우 R 날짜의 숫자 값만 저장됩니다. 이것은 반짝이는 테이블에도 나타납니다. 표와 .csv 파일에서 올바르게 형식을 지정하는 방법을 가르쳐주세요.

아래 코드를 검토하기 전에 Headers Date, A, B가있는 .csv 파일이 저장되어 있다는 것을 알고 있어야합니다.이 파일을 "log"라고 부르 자고 로컬로 저장됩니다. 다음은 코드입니다.

library(shiny) 

log <- read.table("V:\\My\\Path\\log.csv",sep=",",header=T) 

ui <- fluidPage(

    sidebarLayout(

    sidebarPanel(width=2, 

       #Enter Date 
       dateInput("date","Date",min="2016-07-04", max = "2017-07-04"), 

       #Enter Combo 
       selectInput(inputId = "a", "A", c("Choose one" = "","A1", "A2", "A3"), multiple = FALSE, selectize = TRUE, width = NULL, size = NULL), 

       #Enter Number 
       numericInput(inputId = "b", "Favorite Number", NULL, min = 0, max = NA), 

       #Enter Submit to write info to file 
       actionButton(inputId = "submit", "Submit", icon = NULL, width = NULL) 

       ), 

    mainPanel(
     # Application title 
     titlePanel("Read Date"), 
     tableOutput("summary")) 
) 
) 


server <- function(input, output) { 
    #Create vector of current trial results 
    data <- eventReactive(input$submit, {   
    cbind(input$date,input$a, input$b) 

    }) 

    #Append current trial results to master list 
    observeEvent(input$submit, { 
    write.table(data(), file="V:\\My\\Path\\log.csv", sep=",", col.names= FALSE, row.names=F, append = T) 

    }) 

    #Create datatable variable reading in latest log 

    datatable <- eventReactive(c(input$agent,input$submit), {   #Putting both reactive variables allow to see dataset without running and see updated dataset after running. 
    data.frame(read.table("V:\\My\\Path\\log.csv",sep=",",header=T)) 

    }) 

    #Create Table 

    output$summary <- renderTable({ 

    datatable() }, digits=2,align = "cccc") 

} 

shinyApp(ui = ui, server = server) 

대답은 문자로 로그 파일에 쓰고 문자로 다시 읽는 것 같습니다. 나는 이것을 할 수 없다. 나는 올바른 길을 가고 있는가? 내가 배우므로 코드 개선 방법에 대한 다른 제안을 할 것입니다.

답변

1

나는 마침내 간단한 해결책을 찾아 냈습니다. 나는 as.character()이 트릭을 할 것으로 보인다 추가

data <- eventReactive(input$submit, {   
cbind(as.character(input$date),input$a, input$b)) 

data <- eventReactive(input$submit, {   
cbind(input$date,input$a, input$b) 

에서 dataframe를 빌드 할 때

난 그냥 코드를 변경했습니다. 이것이 나중에 결과를 가져올 지 모르겠지만 표시된 테이블은 이제 멋지게 보입니다.

관련 문제