【问题标题】:Unable to show data table output in conditional shiny app无法在有条件的闪亮应用程序中显示数据表输出
【发布时间】:2020-02-28 09:03:44
【问题描述】:

有人可以帮助我吗?

我已经尝试查看不同的教程,以及 Stack 上以前的问题/答案。但没有什么能帮到我。

我正在创建一个闪亮的应用程序,它将根据输入值显示不同的输出(数据表)。

到目前为止,这是我的代码:

library(shiny)
library(DT)

# Define UI for miles per gallon app ----
ui <- pageWithSidebar(

  # App title ----
  headerPanel("Clients per Township - Aggregation"),

  # Sidebar panel for inputs ----
  sidebarPanel(
    helpText("Mean client's penetration (Number of Clients/Number of inhabitants) = 0.0089"),
    selectInput("Choice", "Do you want to have a list of townships with client's penetration above or under the mean?", c(" ", "Above","Under"))),

  # Main panel for displaying outputs ----
  mainPanel(
    conditionalPanel(
      'input.Choice === "Above"',
      DT::dataTableOutput("more_table")
    ),
    conditionalPanel(
      'input.Choice === "Under"',
      DT::dataTableOutput("less_table")
    )
  )
)


# Define server logic to plot various variables against mpg ----
server <- function(input, output) {

  more_table = DT::renderDataTable({
    more_than_mean
  })


  less_table = DT::renderDataTable({
    less_than_mean
  })


}

shinyApp(ui, server)

数据表 more_than_mean 和 less_than_mean 是先前计算的。

当我运行应用程序时,我没有收到错误消息。但是没有显示输出。 有人可以帮助我吗?我不明白为什么在我运行应用程序时没有显示这两个表。

谢谢!

【问题讨论】:

    标签: r shiny conditional-statements


    【解决方案1】:

    所以在再次仔细查看我的代码后,我发现了我的(愚蠢的)错误。 我只忘记了输出表名称前的“输出$”!

    library(shiny)
    library(DT)
    
    # Define UI for miles per gallon app ----
    ui <- pageWithSidebar(
    
      # App title ----
      headerPanel("Clients per Township - Aggregation"),
    
      # Sidebar panel for inputs ----
      sidebarPanel(
        helpText("Mean client's penetration (Number of Clients/Number of inhabitants) = 0.0089"),
        selectInput("Choice", "Do you want to have a list of townships with client's penetration above or under the mean?", c(" ", "Above","Under"))),
    
      # Main panel for displaying outputs ----
      mainPanel(
        conditionalPanel(
          'input.Choice === "Above"',
          DT::dataTableOutput("more_table")
        ),
        conditionalPanel(
          'input.Choice === "Under"',
          DT::dataTableOutput("less_table")
        )
      )
    )
    
    
    # Define server logic to plot various variables against mpg ----
    server <- function(input, output) {
    
      output$more_table = DT::renderDataTable({
        more_than_mean
      })
    
    
      output$less_table = DT::renderDataTable({
        less_than_mean
      })
    
    
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-11
      • 1970-01-01
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 2019-11-04
      • 2023-01-28
      • 2014-09-04
      相关资源
      最近更新 更多