【发布时间】:2019-03-10 09:13:42
【问题描述】:
我正在尝试构建一个闪亮的应用程序,该应用程序具有多个选项卡,这些选项卡从我使用单选按钮和侧边栏中的 selectizeInput 过滤掉的相同数据中提取。
您可以使用以下代码为第一个热图生成数据:
dat<-expand.grid(2:6,7:20,letters[1:8],LETTERS[1:26])
dat$Var5<-sample(0:200,nrow(dat),replace = T)
names(dat)<-c("WEEKDAY" ,
"HOUR" ,
"MEETING_LOCATION" ,
"COURSE_SUBJECT",
"n.SESSIONS")
dat[,"WEEKDAY"]<-factor(dat[,1],levels = c("2","3","4","5","6"),ordered = T)
dat[,c("MEETING_LOCATION","COURSE_SUBJECT")]<-lapply(dat[,c("MEETING_LOCATION","COURSE_SUBJECT")],as.character)
我可以让界面显示出来,但是我在堆栈上找到的很多示例并不能很清楚地说明我需要如何包装所有函数,而且我知道我已经差不多完成了一个。
我正在使用的闪亮应用代码看起来很像这样:
ui <- fluidPage(
titlePanel("Oh My God Please Help"),
fluidRow(
column(3,
wellPanel(
h4("Filter"),
radioButtons("MEETING_LOCATION",
"Location:",
c("a" = "a",
"b" = "b",
"c" = "c",
"d" = "d",
"e" = "e",
"f" = "f",
"g" = "g",
"h" = "h")),
selectizeInput("COURSE_SUBJECT",
label = "Course Subject: ",
choices = LETTERS[1:26],
selected = NULL,
multiple = T)
))
))
# Show a plot of the generated distribution
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Usage",plotOutput("USAGE")))
# other tabs I need to put in don't pay attention to this
# other tabs I need to put in don't pay attention to this
# other tabs I need to put in don't pay attention to this
)
server <- function(input, output) {
usage.0<-reactive({
dat%>%
dplyr::filter(COURSE_SUBJECT %in% input$COURSE_SUBJECT)%>%
dplyr::filter(MEETING_LOCATION==input$MEETING_LOCATION)%>%
group_by(WEEKDAY,HOUR)%>%
sumarise(TOTAL.SESSIONS = sum(n.SESSIONS))
})
output$USAGE <- renderPlot({
usage.0()%>%
ggplot(aes(x = WEEKDAY,y = HOUR))+
geom_tile(aes(fill = TOTAL.SESSIONS))+
geom_text(aes(label = TOTAL.SESSIONS),colour = "white",fontface = "bold",size = 3)+
scale_fill_gradient(guide = guide_legend(title = "Total Number of\nMeetings"),low = "#00ABE1",high = "#FFCD00")+
theme(axis.ticks = element_blank(),
legend.background = element_blank(),
legend.key = element_blank(),
panel.background = element_blank(),
axis.text.x = element_text(angle = 35, hjust = 1),
panel.border = element_blank(),
strip.background = element_blank(),
plot.background = element_blank())+
xlab("Weekday")+
ylab("Hour")+
ggtitle("Busiest Tutoring Days/Hours")
})
}
# Run the application
shinyApp(ui = ui, server = server)
我认为问题与我(不)渲染情节的方式/地点有关。也许我实际上需要另一个选项卡,所以 R 知道该做什么,我不知道......我知道这可能是非常低效的代码,所以任何帮助都会很好,但主要关注点只是为了得到这个当我从侧边栏/单选按钮中选择数据的子集时显示的热图。
提前谢谢你。
【问题讨论】:
标签: r shiny tabs sidebar reactive