Comece agoraComece grátis

Statuses e finalizando a UI

Um dos princípios de boa UI diz que devemos usar cores de forma intuitiva. Felizmente, o shinydashboard permite definir statuses em alguns elementos do pacote. Isso é feito adicionando um argumento status aos elementos apropriados, como box(), notificationItem(), dropdownMenu(), embora estas duas últimas funções não sejam abordadas neste curso.

Definir status = "success" resulta em coloração verde, status = "danger" resulta em coloração vermelha, status = "warning" é laranja, e assim por diante.

Este exercicio faz parte do curso

Construindo dashboards com shinydashboard

Ver curso

Instruções do exercicio

  • Altere o status da primeira caixa na terceira linha para "success".
  • Consulte as linhas 28 a 33, onde os valores dos ValueBox()s na segunda linha são especificados, e faça o mesmo para os da terceira linha.
  • Defina a saída do objeto plotly chamado "line" na etapa anterior.
  • Renderize o shinydashboard usando o ui e o server que você acabou de definir.

exercicio interativo prático

Tente este exercicio completando este código de exemplo.

header <- dashboardHeader(title = "Portfolio information")
sidebar <- dashboardSidebar(disable = TRUE)

body <- dashboardBody(
          fluidRow(box(selectInput("stock", "Stock name", choices = c("AAPL", "DIS")))),
          fluidRow(valueBoxOutput("name", width = 2), 
                   valueBoxOutput("open", width = 2), 
                   valueBoxOutput("close", width = 2), 
                   valueBoxOutput("high", width = 2), 
                   valueBoxOutput("low", width = 2), 
                   valueBoxOutput("vol", width = 2)),
          # Change status to "success"
          fluidRow(box("This stock is in your portfolio", width = 2, status = "danger"), 
                   valueBoxOutput("open_pct", width = 2), 
                   valueBoxOutput("close_pct", width = 2), 
                   valueBoxOutput("high_pct", width = 2), 
                   valueBoxOutput("low_pct", width = 2), 
                   valueBoxOutput("vol_pct", width = 2)),
          fluidRow(box(plotlyOutput("line")), 
                   box(radioButtons("feature", "Features", 
                       choiceNames = c("Open", "Close", "High", "Low", "Volume"),
                       choiceValues = c("open", "close", "high", "low", "volume")) ) )
          )

ui <- dashboardPage(header, sidebar, body)

server <- function(input, output) {
  output$name <- renderValueBox(valueBox("Stock name", get_name(input$stock), color = "black"))
  output$open <- renderValueBox(valueBox("Open price", most_recent(input$stock, "open"), color = "black"))
  output$close <- renderValueBox(valueBox("Close price", most_recent(input$stock, "close"), color = "black"))
  output$high <- renderValueBox(valueBox("High", most_recent(input$stock, "high"), color = "black"))
  output$low <- renderValueBox(valueBox("Low", most_recent(input$stock, "low"), color = "black"))
  output$vol <- renderValueBox(valueBox("Volume", most_recent(input$stock, "volume"), color = "black"))
  # Specify the values for ValueBoxes in the third row
  output$open_pct <- ___(valueBox("Change", paste0(most_recent_pct(input$stock, "open"),"%"), color = box_color(most_recent_pct(input$stock, "open"))))
  ___ <- ___(___("Change", paste0(most_recent_pct(input$stock, "close"),"%"), color = box_color(most_recent_pct(input$stock, "close"))))
  ___ <- ___(___("Change", paste0(most_recent_pct(input$stock, "high"),"%"), color = box_color(most_recent_pct(input$stock, "high"))))
  ___ <- ___(___("Change", paste0(most_recent_pct(input$stock, ___),"%"), color = box_color(most_recent_pct(input$stock, ___))))
  ___ <- ___(___("Change", paste0(most_recent_pct(___, ___),"%"), color = box_color(most_recent_pct(___, ___))))
  # Plotly object in the fourth row
  ___ <- ___(plot_line(input$stock, input$feature))
}

# Render the dashboard using shinyApp()
___
Editar e Executar Código