【发布时间】:2021-04-16 16:26:03
【问题描述】:
我构建了一个闪亮的应用程序,最终应该可以支持多种语言。
因此,在我的 UI 中,我想多次引用相同的图。
但是,我似乎只能参考 outplut$plot 一次 - 如果我多次这样做,则看不到任何绘图。
所以我的问题是:如何从 UI 中多次引用同一个图?
请在下面找到一个最低限度的工作示例。如果我在 UI 中注释掉“plot2”,它就可以工作。如果我不这样做,两个情节都会消失。
来自柏林的祝福(:
library(shiny)
library(ggplot2)
library(plotly)
y <- c(1:30)
x <- c(1:30)
data <- as.data.frame(cbind(y, x))
plot <- renderPlotly(
ggplotly(
ggplot(data, aes(x=x, y=y)) +
geom_point()
)
)
# Define UI for application that draws a histogram
ui <- fluidPage(
"plot1",
plotlyOutput("plot", width = "100%"),
# "plot2",
# plotlyOutput("plot", width = "100%")
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$plot <- renderPlotly({
ggplotly(
ggplot(data, aes(x=x, y=y)) +
geom_point()
)
})
}
# Run the application
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r user-interface shiny plotly