server.R 的问题:无法在 actionButton 中正确使用 observeEvent

Problem with server.R : not able to use observeEvent in actionButton properly

我对闪亮的应用程序比较陌生,正在尝试制作一个简单的应用程序:虽然我能够 运行 ui.R 正确,但我在 server.R.. ....我想要的是获取滑块的值 "post"(此数字将用作函数 "wbpg" 的参数),select 下拉菜单中的绘图类型并在按下操作按钮 "RUN" 时绘制相应的变量.....当名为 "wbpg(x)" 的函数(其中 "x" 是滑块的值)时,所有结果和绘图都会被保存...当 wbpg(x) 是 运行 它 returns 绘图(这包含下拉菜单中所有绘图的列表)

#UI.R
shinyUI( fluidPage(
  titlePanel(title=h4("Text Mining on  thread",align="centre")),

sidebarLayout(
    sidebarPanel(
  sliderInput("post","1. Choose no. of posts you want to run the model",value = 1, min = 1, max = 30000),
  br(),
  selectInput("plotvar","2. Select the variable you want to plot",choices=c("raw_dat"=1,"content"=2,"barplot"=3,"genderplot"=4,"girlplot"=5,"rawplot"=6,"adjplot"=7,
           "drinkplot"=8,"damageplot"=9,"songplot"=10,"sentimentplot"=11)),
  br(),
  actionButton(inputId="act",label = "RUN!")

  ),

  mainPanel(
    textOutput("out"),
    #tableOutput("tab"),
    plotOutput("hist1")
  )
)
))

这是服务器文件,存在问题的地方:

#server.R
shinyServer(function(input, output) {
    #observeEvent(input$action,wbpage(as.numeric(input$post)))
    #output$data<-renderPrint({str(get(content))})
  observeEvent(input$act,{wbpg(np)})  

  output$out<-renderText(paste("No. of posts mined: ",input$post))

#defaul<-reactiveValues(data=wbpage(3000))
np<-wbpage(as.numeric(input$post))



output$hist1 <- renderPlot({barplot})

}) 
#output$hist1 <- 
    #renderPlot({
      #plots$barplot
    #output$tab<-
  #   renderTable({ 
  #  head(data())
    #})
  #output$hist2 <- renderPlot({
  #hist(rnorm(input$num))
  #raunchyplot
  #})
#}) 

在无法访问您的函数 (wbpg) 的情况下,让我尝试帮助您处理 'observeEvent' 调用返回的值。我认为你的问题是 '})' 在 'observeEvent' 行的位置。单击 'Run' 按钮时您希望发生的所有事情都需要在 '})' 内。如果这不是您需要的,请重述问题。

代替 'observeEvent' 命令,使用以下代码查看每次单击 'Run' 按钮时返回的数据。它显示滑块的值和下拉菜单中的数字。

  observeEvent(input$act,{
    print (paste(input$post,input$plotvar,sep=' '))
  })