【发布时间】:2016-07-23 05:44:33
【问题描述】:
我正在使用dismo::maxent 函数来创建绘图,但问题是它们可能需要很长时间(几分钟)。我想要两个选项卡,一个带有地图和可能性图,另一个显示可变重要性。这是有效的,但我希望在模型运行时在两个选项卡上都有一个等待消息/绘图/屏幕。这是 2 个函数调用,没有循环,所以我只需要一个占位符消息。它需要在每次按下提交按钮后显示,但最初不显示。
这是服务器。R
data <- read.csv("CFR_Vaccine_Map_Corrected.csv")
load("./bioclim_10m.Rdata")
shinyServer(
function(input, output) {
observe({
if (!(is.null(input$checkGroup))) {
print(input$years)
print(input$checkGroup)
year.range <- input$years[1]:input$years[2]
filtered.cases <- which(data$Outbreak %in% input$checkGroup &
data$Year %in% year.range)
maxent.model <- maxent(bioStack, data[filtered.cases,5:4])
print("model comp")
maxent.map <- predict(maxent.model, bioStack)
print("plotting map")
output$map <- renderPlot({
plot(maxent.map, xlab="Longitude", ylab="Latitude")
})
output$significance <- renderPlot({
plot(maxent.model)
})
}
})
}
)
这是 ui.R
shinyUI(fluidPage(
titlePanel("Vaccine-Preventable Outbreaks"),
sidebarLayout(
sidebarPanel(
helpText("Create maximum entropy maps with information from
Council on Foreign Relations data on vaccine-preventable
outbreaks."),
checkboxGroupInput("checkGroup", h3("Category"),
choices = list("Polio" = "Polio",
"Whooping Cough" = "Whooping Cough",
"Measles" = "Measles",
"Mumps" = "Mumps",
"Rubella" = "Rubella",
"Polio" = "Polio",
"Violence" = "Violence")),
sliderInput("years", "Years of interest:",
min = 2007, max = 2016, value = c(2007, 2016), sep=""),
submitButton("Submit")
),
mainPanel(
tabsetPanel(
tabPanel("Map", plotOutput("map")),
tabPanel("Variable Significance", plotOutput("significance"))
)
)
)
))
【问题讨论】: