我创建了一个闪亮的应用程序。交互式柱形图出现故障 - 它没有显示两列,而是显示一列。此外,如果我选择不同的变量,图表不会自动更新。
如果有人可以帮助解决它,我将不胜感激。太感谢了!!
这是代码:
library(shiny)
library(ggplot2)
library(plotly)
a=c("Female","Female","Male","Female","Male")
b=c("Yes","No","No","Yes","No")
c=c("Yes","Yes","Yes","No","No")
Mydata=data.frame(gender=a,SeniorCitizen=b,Churn=c)
ggplot(Mydata)+geom_bar(aes(gender,fill=Churn))+
ggtitle("Categorical Variable vs Target Variable")+theme(plot.title = element_text(hjust = 0.5))
ui = shinyUI(fluidPage(
headerPanel(title="Features Review"),
sidebarPanel(
selectInput("Variable","Select A Categorical Variable",
list("gender"="gender","SeniorCitizen"="SeniorCitizen"
))),
mainPanel(
titlePanel(title="Categorical Variable Visualization"),plotOutput("CPlots"))
))
server = shinyServer(function(input, output) {
output$CPlots = reactivePlot(function(){
ggplot(Mydata)+geom_bar(aes(input$Variable,fill=Churn))+
ggtitle("Categorical Variable vs Target Variable")+theme(plot.title = element_text(hjust = 0.5))
})
})
shinyApp(ui,server)