【发布时间】:2017-09-28 07:25:06
【问题描述】:
我今天已经为此工作了 6 个多小时,我知道这是一个简单的问题,但我无法弄清楚。我想要的是输入一个文件,然后能够使用多个 selectInput 下拉菜单来更改 ggplot 上的输出。这是我目前所拥有的:
用户界面:
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()
})
})
}
【问题讨论】: