onclick功能无法正常运行

时间:2018-10-12 10:38:00

标签: shiny onclick shiny-reactivity

显然我的代码对我来说还不错,我已经运行了一个这样的示例,但是这些 onclick()函数不管如何都无法执行其工作。有人可以帮我吗?

它只是一个带有6个按钮的简单代码。 3个用于绘制散点图,直方图和条形图的按钮,而一个按钮可隐藏输出div,一个按钮可显示输出div,一个按钮可更改输出div的背景。.这些onclick功能不起作用:/

library(shiny)
library(shinyjs)
library(shinyWidgets)

moduleTestUI <- function(id){
  ns=NS(id)

   # Application title
   titlePanel("My First Shiny Program")

   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(

        tags$style(type='text/css'
        , ".btn {padding: 8px; font-size: 120%;background-color: rgb(0, 102, 204);color: white;}"
        ,"div.main{width: 750px;height: 550px;border-style: double;border-width: 10px;border-color:grey; }"
        ),



    tags$div(id=ns("div1"),
        hr(),
        actionButton("btn",id=ns("button1"),label = "Scatter Plot"),
        actionButton("btn",id=ns("button2"),label = "Histogram"),
        actionButton("btn",id=ns("button3"),label = "Bar Plot"),
        hr(),
        br(),
        actionButton("btn",id=ns("button4"),label = "Hide Output"),
        actionButton("btn",id=ns("button5"),label = "Show Output"),
        actionButton("btn",id=ns("button6"),label = "Change Color"))),


      # Show a plot of the generated distribution
      mainPanel(
      br(),br(),br(),
      tags$p(strong("  ***** MY OUTPUT PANEL ***** ")),

      tags$div(id=ns('div2'),class="main")
      )
   )
}


moduleTest <- function(input, output, session){
 #scatter plot
   onclick('button1', 
          plot(mtcars$disp, mtcars$mpg,xlab="Engine displacement",
               ylab="mpg", main="MPG vs engine displacement",
               las=1))
  #or onclick('button1',qplot(disp, mpg, data=mtcars,main="MPG vs engine displacement"))

#histogram 
  onclick('button2',hist(mtcars$disp,xlab="Engine displacement", breaks = 5))

#bar plot
  onclick('button3',barplot(mtcars$disp, main="Graph of displacement", names.arg = mtcars$mpg))

  onclick('button4',hide('div2'))
  onclick('button5',show('div2'))
  onclick('button6',setBackgroundColor("blue"))


#---------- other method 
  #scatter plot
 # observeEvent(input$button1,plot(mtcars$disp, mtcars$mpg,xlab="Engine displacement",
  # ylab="mpg", main="MPG vs engine displacement", las=1))
  #or onclick('button1',qplot(disp, mpg, data=mtcars,main="MPG vs engine displacement"))

  #histogram 
  #observeEvent(input$button2,hist(mtcars$disp,xlab="Engine displacement", breaks = 5))

  #bar plot
  #observeEvent(input$button3,barplot(mtcars$disp, main="Graph of displacement", names.arg = mtcars$mpg))

  #observeEvent(input$button4,hide("div2"))
  #observeEvent(input$button5,show("div2"))
  #observeEvent(input$button6,setBackgroundColor("blue"))


}



ui <- fluidPage(

  useShinyjs(),
  moduleTestUI('test')
)


# Define server logic required to draw a histogram
server <- function(input, output) {

}


# Run the application 
shinyApp(ui = ui, server = server)

0 个答案:

没有答案
相关问题