create app show table realtime from api
Drop files here
or click to upload
# Function to fetch data from API
fetch_api_data <- function() {
# Replace this URL with your actual API endpoint
api_url <- 'https://jsonplaceholder.typicode.com/posts'
# Make API request
response <- tryCatch({
GET(api_url)
}, error = function(e) {
warning('Error fetching data from API: ', e$message)
return(NULL)
})
# Check if request was successful
if (is.null(response) || status_code(response) != 200) {
warning('Failed to fetch data from API')
return(data.frame(
error = 'Failed to fetch data',
timestamp = Sys.time()
))
}
# Parse JSON response
data <- fromJSON(rawToChar(response$content))
# Convert to data frame if not already
if (!is.data.frame(data)) {
data <- as.data.frame(data)
}
return(data)
}
Hi! I can help you with any questions about Shiny and R. What would you like to know?