I am trying to make an app with R shiny and I have a little problem.
What I want is to have 2 inputs. First input contain many variables from data base and the second inputs contain the values of a specific variable.
Ex:
ui = tagList(
shinythemes::themeSelector(),
navbarPage(
theme = "united", # <--- To use a theme, uncomment this
"shinythemes",
tabPanel("Casco 3003",
sidebarPanel(
tags$h5("Deafult actionButton:"),
actionButton("action", "Search"),
radioButtons('format', 'Document format', c('PDF', 'HTML', 'Word'),
inline = TRUE),
downloadButton('downloadReport'),
selectInput("select", h3("Categorii"),
choices = list("By Client Category" = "CLIENT_TYPE", "By Client Type" = "Leasing",
"By Agent Type" = "by_agent_type", "By Vehicle Category" = "Vehicle_Category",
"By Brands Top 10 Cars"="top_10_cars","By Age Of Vehicle Car"="Car_age"),
selected = "CLIENT_TYPE"),
selectizeInput("select2",label = "Vehicle Category",
choices = Casco_l$Vehicle_Category),
selectInput("select21",label = "Client Type",
choices = list("All"= "All","Client Category" = "CLIENT_CATEGORY"),
selected = "All"),
tags$h5("actionButton with CSS class:"),
actionButton("action2", "Action button", class = "btn-primary")
),
mainPanel(
tabsetPanel(
tabPanel("INSIS 3003",
h4("Table"),
tableOutput("table1")
),
tabPanel("Graphics",
plotOutput("plot1"),
plotOutput("plot3"))
)
)
)))
server = function(input, output) {
aggregated <- reactive({
Casco_l = subset(Data,INSR_TYPE==3003)
Casco_l %>%
group_by_(input$select21,input$select) %>%
filter_(input$select2) %>%
summarise("Exposure" = format(round(sum(Expos)), digits = 0, big.mark=","),
"Earned Premium" = format(round(sum(Earned_Premium)), digits = 0, big.mark=","),
"GWP" = format(round(sum(GWP_RON)), digits = 0, big.mark=","),
"Incurred" = format(round(sum(inc)), digits = 0, big.mark=","),
"NO of events" = format(as.numeric(sum(No_ev)), digits = 0, big.mark=","),
"Frequency %" = format((sum(No_ev)/sum(Expos)*100), digits = 2, nsmall =2, big.mark=","),
"Loss Ratio %" = format(as.numeric((sum(inc)/sum(Earned_Premium))*100), digits = 2, nsmall=2, big.mark=","),
"ULR %"= format(as.numeric((sum(inc)/sum(Earned_Premium))*ulr*100),digits = 2, nsmall=2, big.mark=","),
"Avr premium" = format(round(ifelse((sum(Expos)==0),0,(sum(Earnend_Premium)/sum(Expos)))), digits = 0, big.mark=","),
"Avr claim" = format(round(ifelse((sum(No_ev)==0),0,(sum(inc)/sum(No_ev)))), digits = 0, big.mark=",")
)
})
I don't know how to use input$select2 to make the group. Because the app said that "Cars" doesn't exist ("Cars is a value from Vehicle Category variable).
What I am trying to say is that I want a group by a variable (input$select) and by a values (input select$2).
Thank you.
I added a image to show what I am trying to say.
"By Agent Type" is a variable (a column) from dataset exactly like "Client Category". For the first input ("By Agent Type") I want to display all the values, for the second input ("Client Category") I want to could choose between "PF" and "PJ" and display only one (or "PF" or "PJ") but not in the same time.
EDIT:
table(AGENT_TYPE): Broker,Agents, Own Network
table(CLIENT_CATEGORY): PF, PJ
I want to display all values for AGENT_TYPE
and only one value for CLIENT_CATEGORY
and in group_by I do the sum on column.