【发布时间】:2018-12-24 20:09:36
【问题描述】:
我正在处理一个非常复杂的闪亮应用程序,我想在其中创建一个服务器函数内的 UI 输出。 UI 不是那么容易,它依赖于在服务器端创建的许多项目,所以我正在创建它连接 UI 的 HTML 部分。一切正常,直到我遇到plotly 图表。
我创建了一个更简单的应用版本,以便更容易理解我的问题。
通常我会这样做:
library("shiny")
library("plotly")
library("dplyr")
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
),
mainPanel(
plotlyOutput("distPlot1"),
plotOutput("distPlot2")
)
)
)
server <- function(input, output) {
output$distPlot1 <- renderPlotly({
x <- faithful[, 2]
plot_ly(x = x, type = "histogram")
})
output$distPlot2 <- renderPlot({
x <- faithful[, 2]
hist(x)
})
}
shinyApp(ui = ui, server = server)
获得这个:
但是当我开始像这里一样在服务器端创建 ui 时(编辑部分在 ui 中包含更多 div):
library("shiny")
library("plotly")
library("dplyr")
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
),
mainPanel(
htmlOutput("ui1"),
uiOutput("ui2")
)
)
)
server <- function(input, output) {
output$distPlot1 <- renderPlotly({
x <- faithful[, 2]
plot_ly(x = x, type = "histogram")
})
output$distPlot2 <- renderPlot({
x <- faithful[, 2]
hist(x)
})
output$ui1 <- renderUI({
show <- h1("lfkhg")
show <- paste0(show, plotlyOutput("distPlot1") %>% as.character())
HTML(show)
})
output$ui2 <- renderUI({
show <- h1("lfkhg")
show <- paste0(show, plotOutput("distPlot2") %>% as.character())
HTML(show)
})
}
# Run the application
shinyApp(ui = ui, server = server)
情节情节没有出现...
你知道为什么以及如何处理这个问题吗?
【问题讨论】:
标签: html r shiny plotly r-plotly