我是Shiny的新手,所以对不起,我深表歉意。我正在尝试通过Shiny制作交互式折线图,以便可以从下拉列表中选择一个国家,然后随附的折线图可以显示该国1987年至2015年的10万自杀人数是如何变化的。输入部分正确,但是我正在努力编码适当的输出图。更具体地说,我不确定在哪里引入它的反应性部分(我将input $ country放在哪里?)。
|year| |age group| |country | |Suicides Per Age Group Per 100K Population|
|----| |---------| |---------| |------------------------------------------|
|1987| |5 - 14 | |Argentina| |.47 |
|1987| |5 - 14 | |Australia| |.28 |
|1987| |5 - 14 | |Austria | |.44 |
library(shiny)
library(tidyverse)
# UI
ui <- fluidPage(selectInput(inputId = "country",
label = "Choose a Country",
choices = data$country[!duplicated(data$country)]), # list of non-duplicated countries
plotOutput("line"))
server <- function(input, output) {
output$line <- renderPlot({ggplot(dash_plot_data,
aes(year,
`Suicides Per Age Group Per 100K Population`,
color = age, group = age,
aes())) +
geom_line()
})
}
# View App
shinyApp(ui, server)
同样,我不确定在哪里插入input $ country部分。任何帮助将不胜感激。
尝试以下方法:
library(shiny)
library(dplyr)
library(ggplot2)
ui <- fluidPage(
selectInput(inputId = "country",
label = "Choose a Country",
choices = unique(data$Country)),
plotOutput("line")
)
server <- function(input, output) {
output$line <- renderPlot({
ggplot(data %>% filter(Country == input$country),
aes(year, `Suicides Per Age Group Per 100K Population`,
color = age, group = age)) + geom_line()
})
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句