Skip to content

Commit

Permalink
gravando videos
Browse files Browse the repository at this point in the history
  • Loading branch information
williamorim committed May 17, 2024
1 parent 51b878a commit dcfc9ed
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 61 deletions.
Binary file modified curso_gravado/.DS_Store
Binary file not shown.
29 changes: 20 additions & 9 deletions curso_gravado/scripts/25-observe-update.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library(shiny)

ui <- fluidPage(
titlePanel("Validação"),
titlePanel("observe + update"),
sidebarLayout(
sidebarPanel(
selectInput(
Expand All @@ -12,8 +12,8 @@ ui <- fluidPage(
selectInput(
inputId = "carro",
label = "Carro",
choices = c("Carregando..." = "")
),
choices = ""
)
),
mainPanel(
)
Expand All @@ -24,16 +24,27 @@ server <- function(input, output, session) {

observe({
carros <- mtcars |>
dplyr::filter(cyl == input$cyl) |>
rownames() |>
sort()
dplyr::filter(cyl == input$cyl) |>
row.names()

updateSelectInput(
session,
"carro",
inputId = "carro",
choices = carros
)
})





}

shinyApp(ui, server)
shinyApp(ui, server)








Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ server <- function(input, output, session) {
observeEvent(input$salvar, {
tibble::tibble(
nome = input$nome,
data_nascimento = input$data_nascimento,
data_nasc = input$data_nascimento,
estado = input$estado
) |>
write.table(
"dados.txt",
file = "dados.txt",
append = TRUE,
sep = ",",
row.names = FALSE,
col.names = FALSE
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,26 @@ server <- function(input, output, session) {
col.names = FALSE
)

showModal(modalDialog(
title = "Dados salvos",
"Seus dados foram salvos com sucesso!",
easyClose = TRUE,
footer = NULL
))
validacao <- TRUE

if (validacao) {
showModal(modalDialog(
title = "Sucesso",
"Os seus dados foram salvos dentro do servidor com sucesso!",
footer = modalButton("Fechar"),
easyClose = TRUE
))
} else {
showModal(modalDialog(
title = "Erro",
"Ocorreu algum erro na hora de salvar!"
))
}

})



}

shinyApp(ui, server)
97 changes: 55 additions & 42 deletions curso_gravado/scripts/28-reactiveVal.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
library(shiny)
library(dplyr)

ui <- fluidPage(
titlePanel("Cadastro de clientes"),
sidebarLayout(
sidebarPanel(
h3("Adicionar cliente"),
h4("Adicionar novo cliente"),
textInput(
"nome",
label = "Nome",
inputId = "nome",
label = "nome",
value = ""
),
textInput(
"email",
inputId = "email",
label = "E-mail",
value = ""
),
actionButton("adicionar", label = "Adicionar cliente"),
actionButton(
inputId = "adicionar",
label = "Adicionar cliente"
),
hr(),
h3("Remover cliente"),
h4("Remover um cliente"),
selectInput(
"id",
inputId = "id",
label = "ID do cliente",
choices = c("Carregando..." = "")
choices = ""
),
actionButton("remover", label = "Remover cliente")
actionButton(
inputId = "remover",
label = "Remover cliente"
)
),
mainPanel(
tableOutput("tabela")
Expand All @@ -33,50 +38,58 @@ ui <- fluidPage(
)

server <- function(input, output, session) {

tab_clientes <- reactiveVal(tibble::tibble(
id = 0L,
nome = "Fulano",
email = "fulano@gmail.com"
id = 1L,
nome = "William Amorim",
email = "william@email.com"
))

observe({
clientes <- tab_clientes() |>
dplyr::pull(id)
observeEvent(input$adicionar, {
novo_id <- as.integer(max(tab_clientes()$id) + 1)
nova_tabela <- tab_clientes() |>
tibble::add_row(id = novo_id, nome = input$nome, email = input$email)

updateSelectInput(
session,
"id",
choices = clientes
tab_clientes(nova_tabela)

showModal(
modalDialog(
title = "Sucesso",
"Cliente adicionado com sucesso"
)
)
})

observeEvent(input$remover, {
if (!input$id %in% tab_clientes()$id) {
showModal(modalDialog(
title = "Erro",
"ID não encontrado",
footer = modalButton("Fechar"),
easyClose = TRUE
))
} else {
nova_tab <- tab_clientes() |>
dplyr::filter(id != input$id)
tab_clientes(nova_tab)
}
output$tabela <- renderTable({
tab_clientes()
})

observeEvent(input$adicionar, {
novo_id <- max(tab_clientes()$id) + 1L
nova_tab <- tab_clientes() |>
tibble::add_row(id = novo_id, nome = input$nome, email = input$email, .before = 1)
tab_clientes(nova_tab)
observe({
ids <- sort(tab_clientes()$id)

updateSelectInput(
inputId = "id",
choices = ids
)
})

output$tabela <- renderTable({
tab_clientes()
observeEvent(input$remover, {

nova_tabela <- tab_clientes() |>
dplyr::filter(id != input$id)

tab_clientes(nova_tabela)

})



}

shinyApp(ui, server)
shinyApp(ui, server)






17 changes: 16 additions & 1 deletion curso_gravado/scripts/dados.txt
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
"William Nilson de Amorim",2024-05-10,"Pará"
"William Amorim" 2024-05-17 "Pará"
"William Amorim" 2024-05-01 "Pará"
"William Amorim" 2024-05-01 "Pará"
"William Amorim" 2024-05-01 "Pará"
"William Amorim" 2024-05-01 "Pará"
"William Amorim" 2024-05-01 "Pará"
"William Amorim" 2024-05-01 "Pará"
"William Amorim" 2024-05-01 "Pará"
"William Amorim",2024-05-17,"Pará"
"William Amorim",2024-05-17,"Pará"
"William Amorim",2024-05-17,"Pará"
"",2024-05-17,"Pará"
"",2024-05-17,"Pará"
"",2024-05-17,"Pará"
"",2024-05-17,"Pará"
"",2024-05-17,"Pará"

0 comments on commit dcfc9ed

Please sign in to comment.