I'd like to make the selection of variables (year
,seasonType
,dayNight
and homeFinalRuns
) inside the baseball
public data from BigQuery without downloading all data. I try to use the reactive()
variables as a filter for the target levels without success because the complete baseball
is always complete downloading and not just read when my Shiny starts I have the output:
Listening on http://127.0.0.1:7377
Downloading first chunk of data.
Received 4,179 rows in the first chunk.
Downloading the remaining 757,439 rows in 242 chunks of (up to) 3,134 rows.
The code that I try is:
library(shinythemes)
library(dplyr)
library(ggplot2)
library(bigrquery)
# Open a public BigQuery dataset eg. "baseball"
bq_con <- dbConnect(
bigrquery::bigquery(),
project = "bigquery-public-data",
dataset = "baseball",
billing = "my_project_id"
)
bigrquery::dbListTables(bq_con) # List all the tables in BigQuery data set
# My email google option
1
#[1] "games_post_wide" "games_wide" "schedules"
#
# Selection of target data set
dataset <- dplyr::tbl(bq_con,
"games_wide") # connects to a table
# Create the shiny dash
ui <- fluidPage(
theme = shinytheme("cosmo"),
titlePanel(title="My Baseball Dashboard"),
sidebarLayout(
sidebarPanel(
selectInput(inputId = "selectedvariable0",
label = "Year",
choices = c(unique(dataset$year)),selected = TRUE ),
selectInput(inputId = "selectedvariable1",
label = "Season",
choices = c(unique(dataset$seasonType)),selected = TRUE ),
selectInput(inputId = "selectedvariable2",
label = "Period",
choices = c(unique(dataset$dayNight)),selected = TRUE ) ,
selectInput(inputId = "selectedvariable3",
label = "Final Runs",
choices = c(unique(dataset$homeFinalRuns)),selected = TRUE )
),
mainPanel(
textOutput("idSaida"),
fluidRow(
splitLayout(plotOutput("myplot")))
)
)
)
server <- function(input, output){
currentvariable0 <- reactive({input$selectedvariable0})
currentvariable1 <- reactive({input$selectedvariable1})
currentvariable2 <- reactive({input$selectedvariable2})
currentvariable3 <- reactive({input$selectedvariable3})
observe({
if(currentvariable2()=="D"){
output$myplot <- renderPlot({
#Create the plot
ggplot(data=dataset, aes(x=currentvariable0(), y=currentvariable3())) +
geom_bar(stat="identity")
})
} else {
#Create the plot
ggplot(data=dataset, aes(x=currentvariable0(), y=currentvariable3())) +
geom_bar(stat="identity")
}
}) #end of observe function.
}
shinyApp(ui, server)
#
Please, any help for solving it?