我试图在同一页面上绘制4个不同的图表,使用闪亮的+ ggvis。侧边栏有3个selectizeInput
控件,其中一个设置参数,一个按钮触发绘图。所有数据都从mysql数据库中获取,并且也会根据数据库的内容生成选择性输入(每个数据取决于之前的数据)。
现在,我想添加一个复选框,当勾选时,将使所有4个图具有相同的最大值。但是,当我尝试这样做时,我会得到类似的东西:
.getReactiveEnvironment()$ currentContext()中的错误: 没有活动的反应上下文,不允许操作。 (你试图做一些只能在反应式表达式或观察者内部完成的事情。)
我应该做些什么才能获得相同的最大值(在获得过滤后的数据之前我不会事先知道,也就是说,最大值是数据依赖的)?
我的代码的骨架如下:
shinyUI(fluidPage(
fluidRow(column(2,
wellPanel(
selectizeInput('ci_select', '1. Instance:', choices = cis,
options = list(
placeholder = 'Please select a instance below',
onInitialize = I('function() { this.setValue(""); }')
)),
## two more selectizeInput, for 'runid_select' and 'setup_select'
...
checkboxInput('maximums', 'Use same maximum', TRUE),
actionButton("go_button", "Plot"))),
column(10,
fluidRow(
column(6, ggvisOutput('tl')),
column(6, ggvisOutput('tr'))),
fluidRow(
column(6, ggvisOutput('bl')),
column(6, ggvisOutput('br')))))))
shinyServer(function(input, output, clientData, session) {
observe({
if (input$ci_select != "") {
# ... query db and fill runids
updateSelectInput(session, "runid_select", choices = runids)
}
})
# ... similar to the above for runid and setup
plot_data <- reactive({
input$go_button
ci <- isolate(input$ci_select)
# ... some checks ...
# ... extract values from input$setup in num_machines, num_volumes, vol_size ...
r <- data %>%
filter(ci == local(ci), runid == local(runid)) %>%
# ... and a lot of other filtering
collect()
})
max_read_bandwidth <- reactive({
maxx <- read_data %>% summarise(maxx=max(read_bandwidth))
maxx[1]$maxx
})
max_write_bandwidth <- reactive({
maxx <- read_data %>% summarise(maxx=max(write_bandwidth))
maxx[1]$maxx
})
max_bandwidth <- reactive({
max(max_read_bandwidth, max_write_bandwidth)
})
plot_data %>%
filter(fio_type=='read') %>%
ggvis(~fio_bs, ~read_bandwidth) %>%
layer_points() %>%
scale_numeric("y", domain=c(0, ifelse(input$maximums, max_bandwidth(), max_read_bandwidth()))) %>%
bind_shiny("tl")
plot_data %>%
filter(fio_type=='randread') %>%
ggvis(~fio_bs, ~read_bandwidth) %>%
layer_points() %>%
scale_numeric("y", domain=c(0, ifelse(input$maximums, max_bandwidth(), max_read_bandwidth()))) %>%
bind_shiny("tr")