2
今天我一直在爲此工作超過6個小時,而且我知道這是一個簡單的問題,但我無法弄清楚。我想要的是輸入一個文件,然後可以使用多個selectInput下拉菜單來更改ggplot上的輸出。以下是我迄今爲止:如何將fileInput連接到閃存中的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()
})
})
}
謝謝您的迴應!當我使用aes_string時,它會告訴我對象'Sales'不存在。在實際的SAS文件中,它表示爲SALEQ,所以我認爲我需要以某種方式讓SALEQ作爲「銷售」運行? – Tarzan
更新:我能夠呈現圖表。再次感謝你! – Tarzan