0
我正在Shiny中開發應用程序。我想使用提交按鈕來渲染陰謀。如果用戶選中輸入框,我也想打印標籤。我可以通過按鈕渲染圖。但是當複選框被選中時它不起作用。閃亮renderLlotly有兩個條件
下面是代碼:
library(shiny)
library(plotly)
ui <- fluidPage(
actionButton('RUN', 'Run'),
checkboxInput('PrintLab', 'Label', FALSE),
plotlyOutput("plot1")
)
server = function(input, output) {
output$plot1 <- renderPlotly({
req(input$RUN)
isolate({
ggplotly(ggplot(data = mtcars, aes(wt, hp)) +
geom_point(size=1, colour = "grey"))
})
req(input$PrintLab)
isolate({
ggplotly(ggplot(data = mtcars, aes(wt, hp)) +
geom_point(size=1, colour = "grey") +
geom_text(aes(label=wt), size=3, colour = "black"))
})
})
}
runApp(shinyApp(ui, server))