我希望使用响应式数据框来展示多个图形和图表。我有一个数据集,希望能够进行筛选。一旦找到了正确的筛选设置,我想在多个不同的绘图上显示数据 - 如果更改了筛选设置,这些图将会更新。
这或许能够解释我正在尝试做什么:
用户界面:
fluidPage(
sidebarLayout(
sidebarPanel(
checkboxGroupInput("checkGroups",
label = "Include", choices = list("1 star" = 1, "2 star" = 2,
"3 star" = 3, "4 star" = 4,
"5 star" = 5),
selected = list(1, 2, 3, 4, 5)),
checkboxInput("checkbox", "Include Replies"),
actionButton("Button", "Update")
),
mainPanel(
showOutput("plot", "nvd3"),
showOutput("pieplot", "nvd3")
)
)
)
服务器:
rating <- c(2, 3, 5, 4, 1, 5, 3, 1, 4)
date_time <- c("2015-05-14", "2015-05-07", "2015-05-06", "2015-04-11", "2015-01-07", "2014-12-06", "2014-04-11", "2014-01-07", "2013-12-06")
repliesOnly <- c(TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE, TRUE)
data <- data.frame(rating, date_time, repliesOnly)
function(input, output, session) {
load("data.Rdata")
newdata <- reactive({
filter_data <- data
filter_data <- filter_data %>% filter(rating %in% input$checkGroups)
filter_data <- filter_data %>% filter(repliesOnly %in% input$checkbox)
return(filter_data)
})
output$plot <- renderChart({
plot <- nPlot(rating ~ date_time, data = newdata,
type = "multiBarHorizontalChart", dom = 'plot')
return(plot)
})
output$pieplot <- renderChart({
pieplot <- nPlot(rating ~ date_time, data = newdata,
type = "pieChart", dom = 'pieplot')
return(pieplot)
})
}
能否实现?当然我可以为每个图形输出包含过滤器,但我的数据集相当大且我的过滤器相当复杂,因此如果它应该为每个图形计算它,那将需要很长时间。
非常感谢所有的帮助!
showOutput
函数?请确保在发布示例代码之前它是可复制的。 - nrusselldat <- newdata()
的内容,并在绘图命令中使用dat
。 - Rorschachnewdata
后面加上()
,就像你写的那样,然后调用newdata
即可。 - Rorschach