2017-09-28 1 views
2

私はこれを今日6時間以上働いており、それは簡単な問題だと私は知っていますが、私はそれを理解できません。私が望むのは、ファイルを入力し、複数のselectInputドロップダウンメニューを使用してggplotの出力を変更できるようにすることです。ここで私はこれまで持っているものです。fileInputをShinyのggplotにどのように接続すればよいですか?

UI:

ui = dashboardPage(
    dashboardHeader(title = "Apple Financials"), 
    dashboardSidebar(
    fileInput("file1", label = "Upload SAS Data:", accept = ".sas7bdat"), 
    selectInput("x", label = "X-Axis Variable", choices = c("Sales", "Cash", "Assets", "Profits", "R&D", "SG&A")), 
    selectInput("y", label = "Y-Axis Variable", choices = c("Sales", "Cash", "Assets", "Profits", "R&D", "SG&A"), selected = "R&D"), 
    selectInput("scale", label = "Choose the Scale:", choices = c("Levels", "Log 10")), 
    radioButtons("model", label = "Choose the Model:", choices = c("Linear Model", "LOESS", "Robust Linear", "None"), selected = "LOESS"), 
    checkboxInput("ribbon", label = "Standard Error Ribbon", value = TRUE), 
    conditionalPanel(
     condition = "input.model == 'LOESS'", 
     sliderInput("span", label = "Span for LOESS", min = 0, max = 1, value = .75) 
    ) 
), 
    dashboardBody(
    box(width = NULL, height = 415, plotOutput("plots")) 
) 
) 

サーバー:入力が文字列である

server = function(input, output) { 


    observe({ 
    data = input$file1 
     if(is.null(data)) 
     return(NULL) 

    df = read_sas(data$datapath) 
    output$plots = renderPlot({ 
    ggplot(df, aes(x = input$x, y = input$y)) + 
     geom_line() 
    }) 
}) 
} 

答えて

2

として、私たちに必要なaes_stringggplot

server = function(input, output) { 


    observe({ 
    data = input$file1 
    if(is.null(data)) 
     return(NULL) 

    df = read_sas(data$datapath) 
    output$plots = renderPlot({ 
     ggplot(df, aes_string(x = input$x, y = input$y)) + 
     geom_line() 
    }) 
    }) 
} 
shinyApp(ui, server) 

enter image description here

注:デモンストレーションのために、SASファイルの代わりにcsvファイルをアップロードしています

+0

ありがとうございます! aes_stringを使用すると、オブジェクト 'Sales'が存在しないことがわかります。実際のSASファイルではSALEQと表記されているので、何とかSALEQを「Sales」として実行させる必要があると思います。 – Tarzan

+1

更新:私はグラフをレンダリングすることができました。ありがとうございました! – Tarzan

関連する問題