【问题标题】:Valuebox with a single date of a table具有表的单个日期的值框
【发布时间】:2021-08-24 23:55:52
【问题描述】:

我正在尝试使用表格的单个日期来做一个闪亮的值框。我的桌子是这样的:

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 行中的值。

【问题讨论】:

  • 我建议你先重新格式化你的代码。而且我注意到您正在尝试在自己的响应式中使用df1,它不会输出任何内容。如果您可以定义df1 反应式,那么您可以执行return(valor)。你不应该使用 valor() 因为它位于 valueBox

标签: r shiny


【解决方案1】:

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

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-01
    相关资源
    最近更新 更多