我有一系列(100多个)情节,我想根据什么犯罪和&amp ;;用户选择(反应)
的年份这些图已经以这种格式命名:" CrimeDataA01"对于2001年的攻击," CrimeDataM02" 2002年的谋杀案等等。
已经定义了这些图,并且在服务器文件中的shinyServer(函数(输入,输出))之前粘贴了它们的代码。
我试图让Shiny打印正确的情节,具体取决于用户选择的犯罪和年份。这是我的server.r代码:
shinyServer(function(input, output) {
crime2 <- switch(input$select,
"Assault" = "A",
"Burglary" = "B",
"Car Theft" = "MT",
"Grand Larceny" = "G",
"Murder" = "M",
"Rape" = "R",
"Robbery" = "RO")
year2 <- switch(input$Slider,
"2000" = "00",
"2001" = "01",
"2002" = "02",
"2003" = "03",
"2004" = "04",
"2005" = "05",
"2006" = "06",
"2007" = "07",
"2008" = "08",
"2009" = "09",
"2010" = "10",
"2011" = "11",
"2012" = "12",
"2013" = "13",
"2014" = "14",
"2015" = "15")
output$plot <- plot(paste0("CrimeData", crime2, year2))
})
})
这是我的ui.R代码:
library(shiny)
shinyUI(fluidPage(
sidebarLayout( position = "right",
sidebarPanel(
selectInput("select", label = h3("Select Crime"),
choices = list("Assault" = 1, "Burglary" = 2, "Car Theft" = 3, "Grand Larceny" = 4, "Murder" = 5, "Rape" = 6, "Robbery" = 7))
),
mainPanel(
textOutput("text1"),
h1("NYC Crime Over Time", align = "center"),
sliderInput("Slider", "Year", 2000, 2015, 2000),
print(plot)
))))
我已经搞砸了这么多,我不知道什么是上升或下降。我只是想调用正确的情节并显示它
答案 0 :(得分:0)
如果我的问题正确,您正在寻找以下代码: 请注意,我只定义了CrimeDataA00和CrimeDataA01,其他图表似乎已在本地保存。 除了Brandon关于查看renderImage()或renderPlot()的建议之外,你应该熟悉reactives()和get()。祝你好运!
setTimeout(function(){
$(".alert").each(function(index){
$(this).delay(200*index).fadeTo(1500,0).slideUp(500,function(){
$(this).remove();
});
});
},2000);