Bom dia.
Pergunta sobre boas praticas em shiny. Se um widget de inputs, as opções vem de um conjunto de dados, que precisa ser lido/consultado de algum lugar, isso eu devo fazer: (1) antes da UI, exemplo abaixo; (2) dentro da UI, (3) no server e usar funções tipo updateSelectInput()
(4) nda?
library(shiny)
library(shinyWidgets)
#> Warning: package 'shinyWidgets' was built under R version 4.0.5
library(tidyverse)
opt = mtcars %>%
dplyr::select_if(is.numeric) %>%
colnames()
ui <- fluidPage(
radioGroupButtons(
inputId = "Id070",
label = "Variavel X",
choices = opt,
justified = TRUE,
checkIcon = list(
yes = icon("ok",
lib = "glyphicon"))
),
radioGroupButtons(
inputId = "Id071",
label = "Variavel Y",
choices = opt,
justified = TRUE,
checkIcon = list(
yes = icon("ok",
lib = "glyphicon"))
),
plotOutput('plot')
)
server <- function(input, output, session) {
output$plot = renderPlot({
mtcars %>%
ggplot(aes_string(x = input$Id070, y= input$Id071))+
geom_point()
})
}
shinyApp(ui, server)
#>
#> Listening on http://127.0.0.1:4970
Created on 2021-10-04 by the reprex package (v2.0.0)