【问题标题】:renderDataTable not working when data pulled from Redshift从 Redshift 提取数据时,renderDataTable 无法正常工作
【发布时间】:2018-11-13 21:32:50
【问题描述】:

我有一个 shinydashboard(在这里使用 shinydashboard 包),我从用户那里获取用户名和密码的输入,使用它连接到 Redshift,使用他的凭据执行 Redshift 查询,然后想要显示查询的输出作为数据表。

不知何故,当我这样做时,查询的输出不显示,它失败而没有抛出任何错误。

以下是代码的摘录:

library(shinydashboard)
library(DBI)
library(shiny)
library(shinyjs)
library(RPostgreSQL)
library(stringi)
library(data.table)
library(DT)
library(dplyr)
    ui <- dashboardPage(
     dashboardHeader(title = "Basic dashboard"),
     dashboardSidebar(
       sidebarMenu(
         menuItem("Connect to RedShift", # 1, variables in this will start with menu_1_
         tabName = "connect_to_RS"
          ))),
     dashboardBody(
        tabItems(
          tabItem(tabName = "connect_to_RS",
                tabBox(
                  title = "",width = 12,
                  tabPanel(title = "Connection to Redshift", 
                  #declare 2 text inputs and submit button
                  fluidRow(
                     column(3,offset = 0,
                     textInput(inputId = "menu_1_tab_1_ltst_qtr",label = "Most Recent Quarter")),
                     column(3,offset = 0,
                                    textInput(inputId = "menu_1_tab_1_RS_user",label = "Redshift Username")),
                     column(3,offset = 0,
                     passwordInput(inputId = "menu_1_tab_1_RS_pwd",label = "Redshift Password")),
                     column(12,
                     submitButton(text = "Submit"))
                     ),
                     mainPanel(
                             dataTableOutput("menu_1_tab_1_table_1")

                           )
                  )
      )
    ))))
    server <- function(input, output) {



        conn <- reactive({
            RPostgres::dbConnect(
            drv = RPostgres::Postgres(),
            host = "xxxx",
            port = xxxx,
            dbname = 'xx',
            user = input$menu_1_tab_1_RS_user,
            password = input$menu_1_tab_1_RS_pwd)
            })
            ltst_qtr_data <- reactive({RPostgres::dbGetQuery(conn(),given_sql_query)  })
output$menu_1_tab_1_table_1 <- renderDataTable({
    expr = ltst_qtr_data()
  })
}
shinyApp(ui,server)

注意:如果我将 renderTable 函数与 tableOutput 函数一起使用,则代码确实有效,并且显示了表格。但我想将 dataTableOutput 函数与 renderDataTable 输出一起使用。

【问题讨论】:

    标签: r shiny shinydashboard rpostgresql


    【解决方案1】:

    语法看起来不错,我猜你的 ltst_qtr_data 反应变量为空。

    确保这条线正常工作:

     ltst_qtr_data <- reactive({RPostgres::dbGetQuery(conn(),given_sql_query)  })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      相关资源
      最近更新 更多