r - 具有表的单个日期的值框
问题描述
我正在尝试使用表格的单个日期来做一个闪亮的值框。我的表如下所示:
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 行中的值。
解决方案
您可以对数据框进行子集化以获得所需的值。
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)
推荐阅读
- java - 点击 TextInputLayout 无法打开键盘
- mongodb - 如何填充特定模型中的字段?(mongodb)
- laravel - 为什么从 Vue 发送的 Laravel API 请求被取消
- firebase - 获取我的 Firebase Cloud 函数的 IP 地址
- javascript - 如何使用javascript替换所有功能
- reactjs - 使用 react-google-login 和 django-allauth 刷新令牌
- python - 无法将 GPU 与 tensorflow-gpu 一起使用
- asp.net - 无法在两个不同的 Web api 调用之间获取会话值
- javascript - 如何在使用微服务和 AWS 的对话中构建对我的私有图像的访问?
- python - 忽略消息包含特定字符串的警告