【发布时间】:2017-06-14 21:39:50
【问题描述】:
我想根据用户选择的犯罪和年份(反应性)显示一系列(100 多个)情节
情节已经命名,格式如下:“CrimeDataA01”代表 2001 年的突击,“CrimeDataM02”代表 2002 年的谋杀,等等。
地块已经被定义并且它们的代码被粘贴在服务器文件中的 shinyServer(function(input, output) 之前。
我正在尝试让 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)
))))
我已经把它搞砸了,我不知道什么是上升或下降了。我只是希望它调用正确的情节并显示它
【问题讨论】:
-
我一回到家就试试。如果它工作 lmk 你的 venmo
-
将
output$plot重命名为output$MyPlot并使用renderImage()而不是plot()。然后将print(plot)更改为 plotOutput("MyPlot")。请参阅?renderImage中的示例
标签: r shiny shiny-server shinydashboard