Hi there,
I'm pretty new to Shiny. I wonder how I can make the numericinput (inflation rate) time the specific columns in the datatable. In my case, I use "spread" to make the year horizontal and this is the desired output. However, I'm not sure how I should time the numericinput to the column after "spread".
Thank you for your help!
#Load packages
library(shiny)
library(data.table)
library(dplyr, warn.conflicts = FALSE)
library(DT)
#>
#> Attaching package: 'DT'
#> The following objects are masked from 'package:shiny':
#>
#> dataTableOutput, renderDataTable
library(tidyr)
periods <- data.frame(p = c(1:3), start = c(as.Date('2020-01-01', '%Y-%m-%d'), as.Date('2021-01-01', '%Y-%m-%d'),as.Date('2022-01-01', '%Y-%m-%d')),
end = c(as.Date('2020-12-31', '%Y-%m-%d'), as.Date('2021-12-31', '%Y-%m-%d'),as.Date('2022-12-31', '%Y-%m-%d')))
example<-data.frame("Provider" = c("a", "b", "c", "c", "b", "a"), "Network" = c("50k", "45k", "40k", "40k", "45k", "50k"),
"AWP" = c(500, 1000, 1500, 2000, 2500, 3000), "Claim" = c(100, 150, 200, 250, 300, 350), stringsAsFactors = FALSE)
# Define UI for app that draws a histogram ----
ui <- fluidPage(
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
numericInput("p1_inf","Inflation Period 1", 0, min = NA, max = NA),
numericInput("p2_inf","Inflation Period 2", 0, min = NA, max = NA),
numericInput("p3_inf","Inflation Period 3", 0, min = NA, max = NA),
width = 3
),
# Main panel for displaying outputs ----
mainPanel(
DT::dataTableOutput("PLAN_AWP_table")
)
)
)
# Define server logic required to draw a histogram ----
server <- function(input, output) {
output$PLAN_AWP_table <- DT::renderDataTable({
f<-example %>%
group_by(Provider, Network) %>% summarize(total_AWP = sum(AWP)) %>% as.data.frame()
g<-merge(periods, f) %>%
mutate(new_AWP=total_AWP*10) %>%
group_by(p, start,end,Provider, Network) %>%
summarize(new_awp=sum(new_AWP)) %>%
as.data.frame()
PLAN_AWP<- g %>%
rowwise() %>%
mutate(dt_range = paste0('Period ' , as.character(p), '. ', format(start, '%m/%d/%Y'), '-', format(end, '%m/%d/%Y'))) %>%
as.data.frame() %>%
select(Provider, Network,dt_range,new_awp) %>%
spread(key = dt_range,value=new_awp,fill = FALSE)
})
}
shinyApp(ui, server)
Shiny applications not supported in static R Markdown documents
Created on 2020-07-21 by the reprex package (v0.3.0)