html - Plotly 不适用于 HTML 函数
问题描述
我正在处理一个非常复杂的闪亮应用程序,我想在其中创建一个服务器函数内的 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()
在那里,因为没有它它对我有用。另外,如果您想在其中添加更多内容,renderUI
只需使用tagList
并将它们组合在一起,我将h1
根据您的评论添加
library("shiny")
library("plotly")
library("dplyr")
ui <- fluidPage(
sidebarLayout(sidebarPanel(),
mainPanel(
uiOutput("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({
tagList(h1("lfkhg"),plotlyOutput("distPlot1"))
})
output$ui2 <- renderUI({
plotOutput("distPlot2")
})
}
# Run the application
shinyApp(ui = ui, server = server)
推荐阅读
- c# - 使用 NoSql 数据库的本地实例来存储用户设置(Windows 桌面)
- linux - 如何通过 bash 脚本直接在不是最活跃的工作区的工作区上打开程序
- django - 如何从帖子列表视图中请求购物车对象?
- c# - 为什么当我尝试在我的代码中进行空检查时出现错误
- excel - SSIS 自动从数据库生成 Excel 文件
- adb - “adb version”输出中的版本号是什么意思
- laravel - 如果产品仅与一个“子类别”相关,如何获得“主类别”的产品?
- android - W/System.err: java.lang.Exception: FFmpeg 未加载
- python - 使用烧瓶、python、HTML 和 PostgreSQL 加载 Web 应用程序时出现问题;无法连接 python 和 html 脚本以及内部服务器错误消息
- javascript - 光滑的滑块有 12 个项目,slidesToScroll 5 和 slidesToShow 5 不滑动每张幻灯片 5 个项目