我尝试了很多数据结构排列,试图在图中更新数据(例如,子集,预设矩阵)
名称(DATAR):
"Sex" "Age" "Year" "PercViewing.DIVORCED" "PercViewing.MARRIED" "PercViewing.NEVER MARRIED"
单独运行并生成输入$ select时生成所需的绘图。但是,输入$ select似乎不会从ui传递到服务器脚本(如下所示)。
ui.r
library(shiny)
shinyUI(
fluidPage(
headerPanel("Have you seen an X-rated movie\nin the last year?"),
sidebarLayout(
sidebarPanel(selectInput("select","Select marital status to view",paste(choices=names(datar[4:6])))),
mainPanel(img(src="liberos.jpg", height = 200, width = 200),h2("Title here",align = "center"),plotOutput("densPlot"))
)
)
)
server.r
library(shiny)
library(ggplot2)
data<-read.table("/Users/nicole/Dropbox/Shiny/xmoviePerc.csv", sep=",",stringsAsFactors =FALSE
shinyServer(function(input, output){
output$densPlot <- renderPlot({
ggplot(datar, aes(x=input$select,fill=datar$Sex)) +
geom_density(alpha = 0.5,colour=c("yellow")) +
labs(title = "Percent who reported viewing\nsex films") +
ylab("Response density") +
xlab("Percent who report having viewed") +
theme(axis.title = element_text(family="Times", face="bold",colour="darkred", size=rel(1.3))) +
geom_text(data = NULL, x = 20, y = .015, label = input$select,aes(label=text,family="Times")) +
scale_fill_discrete(name="Gender reported") +
theme(legend.title = element_text(colour="black", size=16, face="bold"))
})
})