如何在R Shiny应用程序中获得verbatimTextOutput上的clickevent?

时间:2018-02-26 14:45:37

标签: r shiny

我想在点击这个verbatimTextOutput时显示plotoutput而不是我的verbatimTextOutput。如何更改代码以实现此目的?我没有找到办法获得clickevent。

library(ggplot2)
library(shiny)

ui <- fluidPage(
fluidRow(
  verbatimTextOutput("myFirstText")
  )
)

server <- function(input, output) {

   output$myFirstText=renderText({
   "Click on this text to see a histogram of the AirPassengers-data instead of this very text."
   })

   output$myPlot=renderPlot({
   hist(AirPassengers)
   })

}

shinyApp(ui, server)

1 个答案:

答案 0 :(得分:0)

我不确定是否真的可以做你想做的事。但是你可以使用shinyjs包让你走近。你可以尝试:

ui <- fluidPage(
   shinyjs::useShinyjs(),
   fluidRow(
     a(id = "toggleAdvanced", "Click on this text to see a histogram of the AirPassengers-data instead of this very text.", href = "#"),
     shinyjs::hidden(
       div(id = "advanced",
           plotOutput("myPlot")
       )
     )
   )
 )

 server <- function(input, output) {

   shinyjs::onclick("toggleAdvanced",
                    shinyjs::toggle(id = "advanced", anim = TRUE))

   output$myPlot=renderPlot({
     hist(AirPassengers)
   })

 }

 shinyApp(ui, server)
相关问题