【发布时间】:2021-12-24 02:09:44
【问题描述】:
我希望图表出现在相同的位置 在用户界面中,但图表输出的类型取决于用户选择的内容。该示例不起作用,但可以解释我在寻找什么。
简单示例
library(shiny)
# Define UI
ui <- fluidPage(
# Application title
titlePanel("Title"),
# Sidebar
sidebarLayout(
sidebarPanel(
selectInput("time", "Select time frame", choices = c("Hour", "Minute", "Day", "Month"), selected = "Day")
),
# Show a plot of the generated distribution
mainPanel(
uiOutput("plot")
)
)
)
# Define server
server <- function(input, output) {
output$plot = renderUI({
if(input$time %in% c("Hour", "Minute")){
renderPlot(mtcars %>% ggplot(aes(disp, mpg )) + geom_point())
}
else if(input$time %in% c("Day", "Month")){
renderPlotly(mtcars %>% ggplot(aes(disp, mpg )) + geom_point())
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
如果有可能,请告诉我
【问题讨论】:
标签: r shiny plotly rendering shiny-reactivity