Criar um flexdashboard com shiny

Não estou conseguindo criar um FlexDash


title: "Dados Agropecuário"
date: "r format(Sys.time(), '%d %B, %Y')"
output:
flexdashboard::flex_dashboard:
logo: Logo_48_32.png
favicon: Logotipo.png
theme: cerulean
orientation: rows
vertical_layout: scroll
runtime: shiny



# rsconnect::setAccountInfo(name='evertont', token='2A937D24DDDF8C025105BAF742D90A8B', secret='Qr7zvRxzj7V5I28BPUdziiCFks0BNBzDJNgftOJt') # nolint # nolint

rm(list=ls(all=TRUE))
#install.packages("ff")
library(ff)
library(devtools)
#remotes::install_github("r4ds/shinyslack")
#install.packages("basedosdados")
library(basedosdados)
#devtools::install_github("r-lib/testthat")
#remove.packages("rJava")
#install.packages("rJava", dependencies = TRUE)
#install.packages('patchwork')
library(patchwork)
#install.packages("ggridges")
#install.packages("ggside")
library(terra)
library(rgdal)
library(ggside)
library(ggridges)
library(bitops)
#install.packages("tmap")
library(tmap)
#install.packages("arulesViz")
library(arulesViz)
library(geoR)
#install.packages("igraph", type = "binary")
library(igraph)
library(spatialreg)
library(openxlsx)
library(tseries)
library(dplyr)
library(sidrar)
library(kableExtra)
library(knitr)
library(bslib)
library(DT)
library(xtable)
library(xlsxjars)
library(readxl)
#remotes::install_github("paulofelipe/D3plusR")
library(D3plusR)
#install.packages("xlsx", dependencies = TRUE)
#library(xlsx)
library(tidyverse)
library(tidyr)
library(stringr)
library(abjutils)
library(psych)
library(DescTools)
library(sf)
library(sp)
library(bizdays)
#remotes::install_github("ipeaGIT/geobr", subdir = "r-package")
library(geobr)
library(ggsn)
library(ggplot2)
#install.packages("esquisse")
library(esquisse)
#remotes::install_github("ianmoran11/mmtable2")
library(mmtable2)
#install.packages("hrbrthemes")
library(hrbrthemes)
#install.packages("gtfstools")
library(gtfstools)
library(ggspatial)
library(gridExtra)
library(readxl)
library(kableExtra)
library(htmltools)
library(ggstatsplot)
library(sjPlot)
library(plotly)
library(scales)
library(Quandl)
#devtools::install_github("wilsonfreitas/rbcb") # nolint
#sessionInfo()
library(rbcb)
#install.packages("rb3")
library(rb3)
library(dygraphs)
library(stargazer)
#devtools::install_github("schoulten/tidyipea")
library(tidyipea)
#ls("package:tidyipea")
#devtools::install_github("gomesleduardo/ipeadatar")
library(ipeadatar)
#devtools::install_github("trnnick/TStools")
#remove.packages("tstools")
#install.packages("tstools", dependencies = T)
#devtools::install_github("leripio/tstools")
library(tstools)
#ls("package:ipeadatar")
#install.packages("BETS", dependencies = TRUE)
#remove.packages("BETS")
#library(BETS)
#ls("package:BETS")
library(lubridate)
library(psych)
library(rvest)
library(curl)
library(RcppRoll)
library(GetTDData)
library(GetBCBData)
library(ggthemes)
library(stringr)
library(stringi)
library(gdata)
#install.packages("skimr")
library(skimr)
#install.packages("gtrendsR")
library(gtrendsR)
#ls("package:gtrendsR")
#install_github("ahmedmohamedali/eikonapir")
#install.packages("credule")
#library(credule)
#ls("package:credule")
#devtools::install_github("dyl2/CDS")
#library(creditr)
#ls("package:creditr")
#devtools::install_github("fernote7/ecoseries")
library(ecoseries)
#ls("package:ecoseries")
#devtools::install_github("tbrugz/ribge")
library(ribge)
#install.packages("hrbrthemes")
library(hrbrthemes)
#ls("package:ribge")
#install.packages("broom")
#install.packages("syuzhet")
library(syuzhet)
#install.packages("tidyRSS")
library(tidyRSS)
#install.packages("YieldCurve", repos="http://R-Forge.R-project.org")
library(tidygraph)
library(ggraph)
#devtools::install_github("sctyner/geomnet")
#devtools::install_github("briatte/ggnet")
library(ggnet)
library(GGally)
library(network)
library(sna)
library(flexdashboard)
library(shiny)


Custo<- readr::read_delim("https://portaldeinformacoes.conab.gov.br/downloads/arquivos/CustoProducao.txt") |>   
  trim() |>  
   as_tibble() |> 
   mutate(uf = as.factor(uf),
          produto = as.factor(produto))

Dados

Sidebar {.sidebar}

Chart A


 selectInput(
   inputId = "uf",
   label = "UF",
   choices = unique(sort(Custo$uf))
 )


 selectInput(
   inputId = "produto",
   label = "Cultura",
   choices = unique(sort(Custo$produto))
 )

selectInput(
   inputId = "ano_mes",
   label = "ano_mes",
   choices = unique(sort(Custo$ano_mes))
)


# selectData <- reactive ({
#   Custo[,input$uf, input$produto, input$ano_mes]
# })


  shiny::observeEvent(
  input$uf,{
  shiny::updateSelectInput(
  session,
  inputId = "Cultura",
  choises = Custo %>%
   dplyr::filter(uf %in% input$uf) %>%
       pull(produto) %>%
      unique()
        )
 })
# #
 
 shiny::observeEvent(
     input$cultura,{
     shiny::updateSelectInput(
   session = session,
   inputId = "ano_mes",
   choises = Custo %>%
     dplyr::filter(uf %in% input$uf,
            produto %in% input$cultura) %>%
     pull(ano_mes) %>%
     unique()
       )
 })

  #
# #



Column {data-width="350"}

Chart B


 renderTable({
      Custo %>%
     filter(
     uf == input$uf,
     produto == input$cultura,
     ano_mes == input$ano_mes) %>%
     transmute(unidade_comercializacao = unidade_comercializacao,
            meanvlr_custo_variavel_ha = mean(vlr_custo_variavel_ha),                 meanvlr_custo_variavel_unidade = mean(vlr_custo_variavel_unidade),
            meanvlr_custo_fixo_ha = mean(vlr_custo_fixo_ha),
            meanvlr_custo_fixo_unidade = mean(vlr_custo_fixo_unidade),
            meanvlr_renda_fator_ha = mean(vlr_renda_fator_ha),
            meanvlr_renda_fator_unidade = mean(vlr_renda_fator_unidade)
     ) %>%
   distinct()
 })


 # renderTable({
 #      selectData() |>
 #     transmute(unidade_comercializacao = unidade_comercializacao,
 #            meanvlr_custo_variavel_ha = mean(vlr_custo_variavel_ha),                                         meanvlr_custo_variavel_unidade = mean(vlr_custo_variavel_unidade),
 #            meanvlr_custo_fixo_ha = mean(vlr_custo_fixo_ha),
 #            meanvlr_custo_fixo_unidade = mean(vlr_custo_fixo_unidade),
 #            meanvlr_renda_fator_ha = mean(vlr_renda_fator_ha),
 #            meanvlr_renda_fator_unidade = mean(vlr_renda_fator_unidade)
 #     ) |>
 #   distinct()
 # })



Chart C


# Custo |>
#     filter(
#     uf == "RS",
#     produto == "SOJA",
#     ano_mes == "202201") |>
#     transmute(unidade_comercializacao = unidade_comercializacao,
#            meanvlr_custo_variavel_ha = mean(vlr_custo_variavel_ha),                                             meanvlr_custo_variavel_unidade = mean(vlr_custo_variavel_unidade),
#            meanvlr_custo_fixo_ha = mean(vlr_custo_fixo_ha), 
#            meanvlr_custo_fixo_unidade = mean(vlr_custo_fixo_unidade), 
#            meanvlr_renda_fator_ha = mean(vlr_renda_fator_ha), 
#            meanvlr_renda_fator_unidade = mean(vlr_renda_fator_unidade)
#     ) |> 
# #  select(- municipio, -cod_ibge) |> 
#   distinct()



Aparece o seguinte erro:

utput created: C:/Users/everton.lima/AppData/Local/Temp/RtmpWOI4B7/file1f787aad190a/Dados_Agropecuario.html
Warning: Error in shiny::updateSelectInput: unused argument (choises = Custo %>% dplyr::filter(uf %in% input$uf) %>% pull(produto) %>% unique())
3:
1: rmarkdown::run
Warning: Error in filter: Problem while computing ..2 = produto == input$cultura.
:heavy_multiplication_x: Input ..2 must be of size 2560 or 1, not size 0.
117:
116: signalCondition
115: signal_abort
114: abort
113:
112: signalCondition
111: signal_abort
110: abort
109: dplyr_internal_error
108: mask$eval_all_filter
106: filter_eval
105: filter_rows
104: filter.data.frame
103: filter
102: transmute
101: distinct
100: %>%
99: renderTable [#3]
98: func
85: renderFunc
84: output$outb1e141b4f73ea79b
3:
1: rmarkdown::run

1 Like

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.