I am getting the error: Error in ..stacktraceon..({ : object 'input' not found. This code works correctly if the api key/url is formatted without the inputs. I believe the error is at line 25 and 27 where the input$apikey is switched, or that the shiny app doesn't have a value for those to start with.
The goal of this app is to take api key inputted by user and display it nicely with timevis for a schedule. I tried putting the api call and data cleaning below the server function but that does not work. I appreciate any help.
library(shiny)
library(httr)
library(jsonlite)
library(lubridate)
library(tools)
library(timevis)
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("User Schedule"),
# Input API INFo
textInput(inputId = "apikey1", label = h3("API Key"), value = "enterkey"),
textInput(inputId = "userkey1", label = h3("USER EMAIL"), value = "enteremail"),
submitButton("Update View", icon("refresh")),
hr(),
timevisOutput("timeline"))
#Make API call and prepare Timeline information
options(stringsAsFactors = FALSE)
apikey2 <- input$apikey1
userkey2 <- input$userkey1
master_url <- sprintf("https://%s?api_key= %s",userkey2,apikey2)
my_url <- master_url
my_raw_result <- httr::GET(my_url)
my_raw_result
my_raw_result_text <- content(my_raw_result, "text")
my_raw_result_json <- fromJSON(my_raw_result_text, flatten = TRUE)
my_raw_result_df <- as.data.frame(my_raw_result_json)
dt <- my_raw_result_df
dt[dt==""] <- NA # Replace all blank to NA
dt$start <- as.Date(as.character(dt$Schedule.item.date, 1,10)) # reformat the date field to my preferred format
dt$end <- NA
dt$content <- as.character(dt$schedule.item.type) # formate the content as text characters
# Define server logic required to draw time line
server <- function(input, output) {
output$timeline <- renderTimevis({timevis(dt)})
}
# Run the application
shinyApp(ui = ui, server = server)
input$andoutput$variables are only available in aserver <- function(input, output, session) { ... }construct. (That is, inside of yourserver, not outside/before it.) - r2evans