如何在Shiny app中的仪表板主体中输出数据库表?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Shiny app中的仪表板主体中输出数据库表?相关的知识,希望对你有一定的参考价值。
如何将数据库查询的结果输出到我闪亮的应用程序仪表板中。这是我的代码
library(shiny)
library(shinydashboard)
library(dbConnect)
library(Rmysql)
library(DBI)
library(foreign)
conn <- dbConnect(
drv = RMySQL::MySQL(),
dbname = "shinytest",
host = "localhost",
username = "root",
password = "root")
rs <- dbGetQuery(conn, "Select * from test;")
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody())
server <- function(input, output) {}
shinyApp(ui, server)
现在代码rs <- dbGetQuery(conn, "Select * from test")
确实在控制台窗口中提供输出,但我想在仪表板主体中输出它。我怎样才能做到这一点?
答案
library(shiny)
library(shinydashboard)
library(dbConnect)
library(RMySQL)
library(DBI)
library(foreign)
dbDisconnect(conn)
conn <- dbConnect(
drv = RMySQL::MySQL(),
dbname = "apilogs",
host = "localhost",
username = "root",
password = "root")
rs <- dbGetQuery(conn, "Select * from test;")
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(box(
tableOutput('table')
)))
server <- function(input, output) {
output$table <- renderTable(rs)
}
dbDisconnect(conn)
shinyApp(ui, server)
以上是关于如何在Shiny app中的仪表板主体中输出数据库表?的主要内容,如果未能解决你的问题,请参考以下文章