带有数据集输入的R闪亮仪表板信息框

问题描述 投票:0回答:1

我是的新手,很闪闪,怀疑我遇到了一个简单的问题。

我想要2个信息框,其中一个显示所有类别中的最大数量,而第二个信息框中仅显示最大数量及其总数量的类别。

我尝试了很多事情,但是没有什么能使我成功。

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(

    uiOutput("info_box1"),
    uiOutput("info_box2"),
    uiOutput("rawdata")
  )
)

set.seed(24)
mydf <- data.frame(Type = sample(LETTERS[1:5], 30, replace = TRUE),
                   Amount = sample(10:200, 30, replace = TRUE), 
                   stringsAsFactors= FALSE, check.names = FALSE)


server <- function(input, output) {

  output$info_box1 <- renderUI({
    infoBox("Amount in Total here", input$ "???")
  })

  output$info_box2 <- renderUI({
    infoBox("Class with the hightest amount and amount in total of that class", "input$ function needed?")
  })

  output$rawdata = renderTable({
    mydf
  })


}

# Run the application 
shinyApp(ui = ui, server = server)

有人可以告诉我该怎么做吗?

非常感谢。感谢您的帮助。

r shiny shinydashboard shinyapps
1个回答
0
投票

您应该使用适当的功能,请参见此处:https://rstudio.github.io/shinydashboard/structure.html

app.R

library(shiny)
library(shinydashboard)
library(dplyr)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(

    infoBoxOutput("info_box1"),
    infoBoxOutput("info_box2"),
    tableOutput("rawdata")
  )
)

set.seed(24)
mydf <- data.frame(Type = sample(LETTERS[1:5], 30, replace = TRUE),
                   Amount = sample(10:200, 30, replace = TRUE), 
                   stringsAsFactors= FALSE, check.names = FALSE)


server <- function(input, output) {

  output$info_box1 <- renderInfoBox({
    infoBox("Amount in Total here", sum(mydf$Amount))
  })

  output$info_box2 <- renderInfoBox({
df_output <- mydf %>% group_by(Type) %>% tally()
    infoBox("Class with the hightest amount and amount in total of that class", paste(df_output$Type[max(df_output$n)],max(df_output$n))  )
  })

  output$rawdata = renderTable({
    mydf
  })


}

# Run the application 
shinyApp(ui = ui, server = server)
© www.soinside.com 2019 - 2024. All rights reserved.