I'm a retired professor trying to use R to create online apps for the methods in my widely used textbook. I can handle basic R but tiny is driving me crazy. I'd really appreciate some help with some basic shiny concepts that have escaped me.
The enclosed script illustrates a current problem. It reads a .csv file like the one I've copied below the script and loads it into two selectInputs. It works fine in the body of the script but not if I comment that out and try to do it with my create_date_lists function. I guess I don't know how to use reactive expressions in function calls. I'd appreciate any help you can give me on this,
library(tidyverse)
library(shiny)
library(lubridate)
library(ggplot2)
create_date_lists <- function(t.input){
base.list <-reactive(
as.list(t.input[,1])
)
launch.list <-reactive(
base.list()
)
dates <- c(base.list(),target.list())
return(dates)
}
ui <- fluidPage(
titlePanel("What if? Trend"),
sidebarLayout(
sidebarPanel(
fileInput("upload.file", "Upload trend data file",
multiple = FALSE,
accept = ".csv"),
uiOutput("base.date.output"),
uiOutput("launch.date.output")
),
mainPanel(
tableOutput("date.list")
)
)
)
server <- function(input, output, session) {
# read trend data file
t.input <- eventReactive(input$upload.file, {
read_csv(input$upload.file$datapath)
})
base.list <-reactive(
{
req(t.input())
as.list(t.input()[,1])
}
)
launch.list <- reactive(
base.list()
)
# reactive(
# {
# create_date_lists(t.input())
# }
# )
output$date.list <- renderTable({
base.list()
})
# Specify parameters ----
output$base.date.output <- renderUI({
selectInput("base.date",
label = "Select base date",
choices = base.list(),
selected = "")
})
output$launch.date.output <- renderUI({
selectInput("launch.date",
label = "Select launch date",
choices = launch.list(),
selected = "")
})
}
shinyApp(ui, server)
|date|cases|
|---|---|
|2020_01|21.112|
|2020_02|27.881|
|2020_03|44.051|
|2020_04|70.278|
|2020_05|86.942|
|2020_06|136.395|
|2020_07|256.782|
|2020_08|415.387|
|2020_09|483.024|
|2020_10|545.837|
|2020_11|665.865|
|2020_12|691.893|