【发布时间】:2019-04-12 19:32:47
【问题描述】:
我对 Shiny 和 Plotly 比较陌生,并且有以下代码 sn-p:
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(plotly)
library(odbc)
library(DBI)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Demo"),
#Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 0,
max = 100,
value = 70)
),
# Show a plot of the generated distribution
mainPanel(
tabPanel("Heading", plotlyOutput("tbTable"))
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
QueriedData <- reactive({
connn <- DBI::dbConnect(odbc::odbc(),.connection_string = "XXX", uid = "AB", pwd = "CD")
lat_rec.df <- dbGetQuery(connn, "PQR")
dbDisconnect(connn)
lat_rec.df1
})
output$tbTable <- renderPlotly({
plot_ly(QueriedData(),x = ~TotalCount, y = ~MyScore, type = 'scatter', mode = 'markers')
})
}
# Run the application
shinyApp(ui = ui, server = server)
正如您在上面看到的,我正在绘制我从数据库中读取的数据帧的散点图(如反应函数中所述)。我有几个问题:
- 我想使用滑动条输入作为我的 Y 轴 (MyScore)。我怎么做?我目前无法将滑块(箱)链接到我的绘图图中。我希望散点图根据滑块输入进行更新。
- 我对反应函数有点困惑。这是否意味着每次我更改滑块时,数据库都会被调用(在反应函数中)?它是如何工作的?
- 如果我有其他数据库表要读取和绘制在其他区域,我是否将其包含在反应函数中?请指教。
提前感谢您的帮助!干杯!
【问题讨论】:
-
需要为带有 ui 和服务器的散点图添加更多代码,最后你需要使用渲染图。我只在闪亮的页面上看到了几篇文章。