everyone!
I'm trying hard here to get the data I grouped by the 'fc' function and it was supposed to be in this new dataset 'reac', where I wanted it to be updated when a user input which variable he/she wants to use at shiny's UI (input$x, input$y, input$color). Then I want to use this new reac dataset in ggplot, but the 'aes_string() isn't working, the compiler doesn't recognize the data type as a dataframe and I'm getting a "Can't convert NULL to a quosure" error and "Unknown input:tbl_df" error.
Sorry for the bad english, it isn't my mothertongue! :(
Thanks in advance!
library(shiny)
library(plotly)
library(rsconnect)
library(sidrar)
library(dplyr)
library(ggplot2)
#dados261<-get_sidra(api="/t/261/n2/all/n3/all/v/allxp/p/last%2011/c1/allxt/c2/allxt/c58/1140,1141,1142,1143,1144,1145,1146,1147,1148,1149,1150,1151,1152,1153,2792,2793,3244,3245/d/v93%203")
load("C:/Users/Fausto/Desktop/dados_1.RData")
colnames(dados261)<-c("nt_cod","nt","regiao_cod","regiao","va_cod","va","ano_cod","ano","dom_cod","dom","sexo_cod","sexo","id_cod","id","um_cod","um","valor")
names1 <- c("nt_cod","regiao_cod","va_cod","ano_cod","dom_cod","sexo_cod","id_cod","um_cod")
dados261[names1] <- sapply(dados261[names1],as.numeric)
years<-as.numeric(sort(unique(dados261$ano)))
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
h1("Tabela 261 - SIDRA - Dados Gerais"),
selectInput("x", label = "Eixo x", choices = list("Região" = "regiao", "Idade" = "id", "Sexo" = "sexo", "DomicÃlio" = "dom", "Valores" = "valor"), selected = "regiao"),
selectInput("y", label = "Eixo Y", choices = list("Região" = "regiao", "Idade" = "id", "Sexo" = "sexo", "DomicÃlio" = "dom", "Valores" = "valor"), selected = "valor")
),
mainPanel(
tabsetPanel(
tabPanel("Gráfico de barras",
plotOutput("plot", width = "80%", height = "80%"),
radioButtons("color", label = "Preenchimento", choices = list("Região" = "regiao", "Idade" = "id", "Sexo" = "sexo", "DomicÃlio" = "dom", "Nenhuma" = "id"), selected = "nn", inline = TRUE)),
tabPanel("Série Temporal",
plotOutput("plot2", width = "100%", height = "100%"),
sliderInput("ano", label = "Anos", min = min(years), max= max(years), value=c(min(years),max(years)))
)
)
)
)
)
server <- function(input, output){
fc<- function(data, ...) {
data %>% group_by_(...) %>%
summarise(valor2 = sum(valor, na.rm = TRUE)) -> data
return(data)
}
reac<-reactive({
fc(dados261, input$x, input$y, input$color)
})
output$plot <- renderPlot({
eixox<-as.character(reac()[,1])
eixoy<-as.numeric(reac()$valor2)
eixoz<-as.character(reac()[,2])
p<- reac() %>%
ggplot() +
aes_q(eixox, eixoy, fill= eixoz) +
geom_bar(stat = "identity")
ggplotly(p)
}, height = 600, width = 900)
}
shinyApp(ui = ui, server = server)


