我正在使用带有字符的滑块作为滑块参数(FY17Q1到FY19Q1),并且尝试使用ggplot绘制图形。但是我无法绘制图形。需要一些有关在更改滑块时如何绘制图形的帮助。
我尝试了反应功能,observeEvent,reactorValues
ui <- dashboardPage(
dashboardHeader(title = "Basic Dashboard"),
dashboardSidebar(
sidebarMenu(sliderTextInput("Quarter","Select Quarter:" ,
choices = (File2$Quarter),#To not repeat values in the slidertextinput if the values are not sorted
selected = (File2$Quarter), #values which will be selected by default
animate = FALSE, grid = FALSE,
hide_min_max = TRUE, from_fixed = FALSE,
to_fixed = FALSE, from_min = NULL, from_max = NULL, to_min = NULL,
to_max = NULL, force_edges = FALSE, width = NULL, pre = NULL,
post = NULL, dragRange = TRUE))),
dashboardBody(
fluidRow(
box(solidHeader = TRUE
,collapsible = TRUE,align="center",offset = 2,title = "RiskTier Vs Quater",status = "warning", plotOutput("k", height = "300px"),width = 6)
,
box(solidHeader = TRUE
,collapsible = TRUE,align="center",offset = 4,title = "RiskTier Vs Quater(%)",status = "warning", plotOutput("l", height = "300px"),width = 6)
)))
server <- function(input, output) {
# File2<- File2[-(28:30),]
# # File2$RiskTierDesc = factor(File2$RiskTierDesc, levels=c("High", "Above Normal", "Normal"))
v <- reactiveValues(data = File2)
#
# observeEvent(input$Quarter,{v$mode <- "Quarter"})
# # if(is.null(v$mode))
# # return()
observeEvent(input$Quarter,{
if(input$Quarter[1] == input$Quarter[2]){
updateSliderTextInput(session,"Quarter",selected = c((input$Quarter[1]-1),input$Quarter[2]))
}
})
output$k<- renderPlot({
ggplot(v(),
aes(x=Quarter, y=Freq, group=RiskTierDesc, colour=RiskTierDesc)) +
geom_line(aes(size=RiskTierDesc)) +
geom_point() + ylim(0,2500) +
scale_color_manual(values=c("red","orange","green")) +
scale_size_manual(values=c(1,1,1)) +
labs( x = "Quarter", y = "Frequency") +
geom_text(aes(label = Freq), position = position_dodge(0),vjust = -1) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
})
output$l<- renderPlot({
ggplot(v(),
aes(x=Quarter, y=FreqbyPercent, group=RiskTierDesc, colour=RiskTierDesc)) +
geom_line(aes(size=RiskTierDesc)) +
geom_point() + ylim(0,100) +
scale_color_manual(values=c("red","orange","green")) +
scale_size_manual(values=c(1,1,1)) +
labs( x = "Quarter", y = "Frequency(%)") +
geom_text(aes(label = FreqbyPercent), position = position_dodge(0),vjust = -1) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
})
}
shinyApp(ui, server)
我想获得一个季度到季度的动态图。