on selection of multiple town // server.r
library(RJDBC)
library(dplyr)
library(shiny)
library(ggplot2)
library(scales)
library(shinydashboard)
library(gridExtra)
library(DT)
library(ggthemes)
library(plotly)
library(reshape2)
library(shinyWidgets)
dsn_driver = ""
dsn_database = "" # e.g. "BLUDB"
dsn_hostname = "" # e.g.: "awh-yp-small03.services.dal.bluemix.net"
dsn_port = "" # e.g. "50000"
dsn_protocol = "" # i.e. "TCPIP"
dsn_uid = "" # e.g. "dash104434"
dsn_pwd = ""
jcc = JDBC("", "");
jdbc_path = paste("jdbc:db2://", dsn_hostname, ":", dsn_port, "/", dsn_database, sep="");
conn = dbConnect(jcc, jdbc_path, user=dsn_uid, password=dsn_pwd)
query ="select RETAIL_STR_AREA_WISE.STORE_NM as ST,RETAIL_STORE_AREA_WISE.TOWN_NAME as TOWN_NAME,RETAIL_STORE_AREA_WISE.AREA_NAME as AR,
ROUND(SUM(RETAIL_STR_SALES_MASTER.GRAND_TOTAL),2) as SALES_VALUE
from retail_str_sales_master, retail_store_area_wise
where retail_store_area_wise.store_id = retail_str_sales_master.store_id
GROUP BY
RETAIL_STORE_AREA_WISE.STORE_NM ,
retail_store_area_wise.area_name,
retail_store_area_wise.area_code,
retail_store_area_wise.town_name
ORDER BY RETAIL_STORE_AREA_WISE.STORE_NM,
retail_store_area_wise.area_name"
query1=dbGetQuery(conn,query)
#Dropdown Function
biz = data.frame(
Are=query1$AR,
TOWNNAME=query1$TOWN_N,
Storename=query1$ST,
Salevalue=query1$SALES_VALUE,
stringsAsFactors = FALSE
)
# connection with dash db
shinyServer(function(input, output, session) {
autoInvalidate <- reactiveTimer(50000, session)
output$Box1 = renderUI(selectInput("yr",label = "select a Area NAME",c(unique(isolate(biz$Are)),"pick one"),"pick one"))
output$Box2 = renderUI(
if (is.null(input$yr) || input$yr == "pick one"){return()
}else checkboxGroupInput("sector",
"Select a Town_Name",
choices = c(unique(biz$TOWNNAME[which(biz$Are == input$yr)])),
"pick one")
)
subdata1 = reactive(biz[which(biz$TOWNNAME== input$sector),])
无法在多个选择输入上生成输出,它在一个选择输入上运行良好,但在多个选择
中不运行output$text1 <- renderText({
autoInvalidate()
sprintf("Total value of store per day", input$sector,"sales")
})
output$text2 <- renderText({
autoInvalidate()
sprintf("Total Number of bills per day", input$sector,"sales")
})#not showing data as per the multiple checkbox group input working fine on single input select
output$view = DT::renderDataTable({
autoInvalidate()
if(is.null(input$sector) ){return()
} else if (input$sector == "pick one"){return()
} else
{
autoInvalidate()
subdata1()[,c("TOWNNAME","Storename","Salevalue")]
}
},rownames = FALSE,class = 'cell-border stripe')
output$plot <- renderPlotly({not ploting output as per the multiple checkbox input
autoInvalidate()
if (is.null(input$sector)){return()
} else if(input$sector == "pick one") { return()
} else p <- ggplot(data=subdata1() ,aes(x =Storename, y = Salevalue,group=Storename),environment=environment())+ geom_histogram(stat = "identity",aes(fill = type),fill = "blue")+
geom_smooth() + ggtitle("ggplot")
print(p + theme(axis.text.x =
element_text(size = 10,angle = 45,hjust = 1,vjust = 1))) })
})
// ui.r
library(RJDBC)
library(dplyr)
library(shiny)
library(ggplot2)
library(scales)
library(shinydashboard)
library(gridExtra)
library(DT)
library(ggthemes)
library(plotly)
dashboardPage( dashboardHeader(title =&#34; STORE ANALYTICS&#34;), dashboardSidebar(
sidebarMenu(menuItem("Per Day Sales", tabName = "root", icon = icon("calendar"),uiOutput("Box1"),
uiOutput("Box2")
))
),
dashboardBody(
fluidPage(
displaying output of the ggplot
fluidRow(
box(
width = 20, status = "info", solidHeader = TRUE,
title = textOutput("text1"),
plotlyOutput(paste('plot'))),
#data table output displaying here
box(
width = 8, status = "info", solidHeader = TRUE,
title = "STORE SALES PER MONTH ",
dataTableOutput("view")
)
)
)
)
)