반짝 이는 응용 프로그램을 만들려고합니다. 데이터베이스에 3 개의 테이블이 있습니다. 응용 프로그램은 MySQL에서 데이터 테이블을 검색하고 웹 인터페이스에 팝업합니다. UI 기능에는 모든 선택 사항이 언급되어 있습니다. MySQL에서 데이터를 가져올 때, 나는 readtable 명령을 3 번 작성했습니다. 하나의 읽기 가능 명령문에서 데이터를 검색하는 옵션이 있습니까?mysql에서 반짝이는 테이블에서 데이터를 읽는 방법
library(shiny)
# Define UI for dataset viewer application
ui<-fluidPage(
# Application title.
titlePanel("More Widgets"),
sidebarLayout(
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("table1", "table2","table3")),
numericInput("obs", "Number of observations to view:", 10),
submitButton("Update View")
),
mainPanel(
h4("Observations"),
tableOutput("view")
)
)
)
# Define server logic required to summarize and view the
# selected dataset
server<-function(input, output) {
conn <- dbConnect(drv = RMySQL::MySQL(),dbname = "xxx",host = "localhost",
username = "root",password = "yyy")
on.exit(dbDisconnect(conn), add = TRUE)
table1<- dbReadTable(conn = conn, name = 'table1', value = as.data.frame(table1))
table2<- dbReadTable(conn = conn, name = 'table2', value = as.data.frame(table2))
table3<- dbReadTable(conn = conn, name = 'table3', value = as.data.frame(table3))
# Return the requested dataset
datasetInput <- reactive({
switch(input$dataset,
"table1" = table1,
"table2" = table2,
"table3" = table3
)
})
# Show the first "n" observations
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
on.exit(dbDisconnect(conn), add = TRUE)
}
shinyApp(ui, server)
모두에게 감사드립니다. Joris Gillis, 도와 줘서 고마워. 그것은 당신의 코드 조각을 사용하여 원하는 방식으로 작동합니다 :) –