2017-12-16 22 views
0

데이터 세트에서 관심있는 변수에 대해 svytable을 사용하여 가중치 테이블을 생성하는 반짝이는 앱을 만들려고합니다. 그러나, 나는 "개체 '입력'찾을 수 없습니다"오류를 반환, 어떤 출력을하지 않습니다. 내 문제를 복제하는 코드는 다음과 같습니다.가중치 테이블 출력 Shiny

df <- data.frame(col1 = rnorm(20, 0, 1), col2 = rnorm(20, 2, 2), w = rnorm(20, 1, .2)) 
df.w <- svydesign(id = ~1, data = df, weights = ~w) 

ui <- fluidPage(
     selectInput("v1", "Choose column", colnames(df), selected = "col1"), 
     verbatimTextOutput("table") 
) 
server <- shinyServer(function(input,output){ 
    output$table <- renderPrint({ 
    svytable(~input$v1, df.w) 
    }) 
}) 
shinyApp(ui, server) 

답변

0

당신은 input$v1 이후이 오류는 문자열받을 만 svytableformula을 기대하고있다. 문자열을 수식으로 변환 할 수 있습니다. as.formula

library(shiny) 
library(survey) 

df <- data.frame(col1 = rnorm(20, 0, 1), col2 = rnorm(20, 2, 2), w = rnorm(20, 1, .2)) 
df.w <- svydesign(id = ~1, data = df, weights = ~w) 

ui <- fluidPage(
    selectInput("v1", "Choose column", colnames(df), selected = "col1"), 
    verbatimTextOutput("table") 
) 

server <- function(input, output){ 
    output$table <- renderPrint({ 
    myformula <- as.formula(paste0("~", input$v1)) 
    svytable(myformula, df.w) 
    }) 
} 

shinyApp(ui, server) 
+0

감사합니다. 어떻게 알았어? 또는 더 나은 질문, 어떻게 알 수 있었습니까? 나는 비교적 새로운입니다 – MSD

+0

이것은 실제로 일반적인 문제입니다. 수식은 여기에서했던 것처럼 "동적"으로 만들 때 항상 까다 롭습니다. 디버깅 목적으로 (반짝이는) render 함수 (또는'reactive' expressions) 내부에서'browser()'를 호출 할 수 있습니다. –

+0

나중에 df.w를 저장하는 방법이 있습니까? 내 데이터 세트는 약 1GB이고 df.w를 생성하는 데 시간이 걸릴 수 있으므로 개발중인 반짝이는 앱에서 시간을 절약하고 경험을 향상시킬 수 있습니다. – MSD