首页 > 解决方案 > 具有表的单个日期的值框

问题描述

我正在尝试使用表格的单个日期来做一个闪亮的值框。我的表如下所示:

Color<-c("blanco","blanco","gris","gris","blanco","gris","gris","gris","blanco","blanco","gris","blanco","gris","blanco","gris")
Tipo<-c("gato","gato","gato","perro","perro","perro","perro",
        "buho","buho","buho","buho","tigre","tigre","tigre","tigre")
data<-data.frame(Color,Tipo)

在我的用户界面中

   tabsetPanel(
       position= "left",
     tabPanel("Cancelaciones", icon = icon("window-close"),
                         fluidRow(
                            uiOutput("Box1")),
                        sidebarLayout(sidebarPanel(
                            uiOutput("SelectTipo")
                         ),
                         mainPanel( 
                            plotlyOutput("barplotx"),
                           dataTableOutput("summaryx")
                         ) ) )
                ))

服务器

  output$SelectTipo<-renderUI({
   selectInput("SelectTipo", "Tipo",
            data$Tipo, multiple = T, selected = TRUE) 
  })

df<-reactive({
data %>%
  filter(Tipo %in% input$SelectTipo)
  })  

df1<-reactive({
df2<-df()
df2 %>%
count(Color)%>%
mutate(percent=round(((n/sum(n))*100), digits=2))%>%
arrange(desc(percent))>tmpx
names(tmpx)<- c("Evento","N","Porcentaje")
tmpx


  })
   valor<-df1[1,2] ##### <-----here is the line
 output$Box1 <- renderUI({ 
 valueBox(value = valor(), subtitle = "Valor", ##### <-and here
  icon = icon("check-circle"),
  color = "green")  
 })

我希望值框是第 1 列第 2 行中的值。

标签: rshiny

解决方案


您可以对数据框进行子集化以获得所需的值。

library(shiny)
library(shinydashboard)

ui <- fluidPage({
  uiOutput('Box1')
})

server <- function(input, output) {
  
  valor <- reactive(data)

  output$Box1 <- renderUI({ 
    valueBox(value = valor()[2, 1], #2nd row, 1st column
             subtitle = "Valor", 
             icon = icon("check-circle"),
             color = "green")  
  })
}

shinyApp(ui, server)

在此处输入图像描述


推荐阅读