我一直在尝试将我的滑块(具有年份)与selectInput下拉列表(具有自由度)链接在一起。我一直在获取甜甜圈图,但分布均匀。我希望在下拉菜单中选择选项,并使用滑块更改其趋势。我知道output $ plot2 <-renderPlotly({})中有问题,但不确定是什么。
global.r
df3<- df1[, (names(df1) %in% c("year","region","pf_rol", "pf_ss_homicide","pf_ss_disappearances_fatalities", "pf_ss_women_fgm", "pf_ss_women_inheritance", "pf_religion","pf_association_sport","pf_association_political", "pf_expression_internet", "pf_identity_sex", "ef_legal_judicial", "ef_legal_military", "ef_money_growth", "ef_trade_tariffs_revenue", "ef_regulation_business_start","ef_regulation_business_bribes"
))]
netgraph <- df3 %>%
group_by(year,region)%>%
summarise_all(mean)
longdata <- gather(netgraph, key="freedom_factors", value="value", c("pf_rol", "pf_ss_homicide","pf_ss_disappearances_fatalities", "pf_ss_women_fgm", "pf_ss_women_inheritance", "pf_religion","pf_association_sport","pf_association_political", "pf_expression_internet", "pf_identity_sex", "ef_legal_judicial", "ef_legal_military", "ef_money_growth", "ef_trade_tariffs_revenue", "ef_regulation_business_start","ef_regulation_business_bribes"))
select_ops <- unique(longdata$freedom_factors)
server.r
shinyServer(function(input,output,session){
years <- reactive({
longdata %>%
filter(year == input$yearslong)})
selectfreedom <- reactive({
longdata %>%
filter(freedom_factors == input$variable)})
output$plot2 <- renderPlotly({
donut <- selectfreedom() %>%
group_by(region) %>%
summarise(mean(value)) %>%
plot_ly(labels = ~region, values = ~value) %>%
add_pie(hole = 0.6) %>%
layout(title = "Donut charts using Plotly", showlegend = F,
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
dput(longdata)
})
})
ui.r
dashboardPage(
dashboardHeader(title = "Human Freedom Index", titleWidth = 300),
dashboardSidebar(
sliderInput("years","Select Year:",
min = min(df1$year),
max = max(df1$year),
value = min(df1$year),
step = 1),
selectInput("variable","Select Freedom Factor:",
c("Rule of Law"= "pf_rol",
"Homicides Reported" = "pf_ss_homicide",
"Women Dissapearances"="pf_ss_disappearances_violent",
"Deaths by Terrorism"="pf_ss_disappearances_fatalities",
"Female Mutiliation"= "pf_ss_women_fgm",
"Women Inheritance" = "pf_ss_women_inheritance",
"Freedom of Religion" = "pf_religion")),
dashboardBody(
fluidRow(
box(plotlyOutput("plot2"), width=15, height=400)
)
)
)
)
答案 0 :(得分:0)
我认为您需要此更正-
selectfreedom <- reactive({
years() %>%
filter(freedom_factors == input$variable)})