Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

using dateInput as the date component of a url to scrape from

$
0
0

My goal is an app that scrapes and plots html table data, by user-selected date. Each day of data has one url ending in yyyymmdd , eg:

https://cdec.water.ca.gov/reportapp/javareports?name=PAGE6.20191219https://cdec.water.ca.gov/reportapp/javareports?name=PAGE6.20191216

Once the user selects or changes the date, the app is to build the url and then scrape and visualize the day of data. The scraping/visualizing part works. I'm stuck on the first part, trying to paste the user input date onto the url beginning.

With what I have:

library(shiny)
library(leaflet)
library(shinyjs)
library(shinydashboard)
library(XML)

ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(

dateInput('date',
          label = 'cdec query date:', format = "yyyymmdd",
          value = "2019-12-16" )
          ),

dashboardBody(
tags$style(type = "text/css", "#mapplot {height: calc(100vh - 80px) !important;}"),
leafletOutput("mapplot"),
useShinyjs() ) )

server <- function(input, output) {
 addClass(selector = "body")
 options(shiny.maxRequestSize=225*1024^2)

baseurl <- "http://cdec.water.ca.gov/reportapp/javareports?name=PAGE6."

# append the user-entered yyyymmdd to the base url
url <- reactive({paste0(baseurl, input$date) )}

# scrape data
cdec_swe_table  <- readHTMLTable(url)

# process/tidy/format cdec_swe_table and display results on map
# eg, cdec_swe_table <- cdec_swe_table %>% mutate, filter etc, then st_as_sf() to create spatial object
# all processing/mapping works outside of shiny,
# it's the reactive wrapping (which wrapper(s), how many, where) around
# url/cdec_swe_table I'm missing

}

shinyApp(ui, server)

I get:

Error in (function (classes, fdef, mtable)  : 
unable to find an inherited method for function ‘readHTMLTable’ for 
signature ‘"reactiveExpr"’

I think I'm missing some reactivity fundamentals. Any help greatly appreciated.


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>