【问题标题】:Shiny seesion object is not found when trying to use shinyJS()尝试使用 shinyJS() 时找不到闪亮的视觉对象
【发布时间】:2021-12-30 19:23:43
【问题描述】:

在下面的闪亮应用中,我尝试使用 shinyJS() 隐藏和显示文本,但我得到:

错误:shinyjs:找不到闪亮的会话对象。这通常发生在从不是由 Shiny 会话设置的上下文中调用 shinyjs 函数时。

不要担心数据集不存在,这只是一个例子

## app.R ##
library(shiny)
library(shinydashboard)
library(dplyr)
library(shinyjs)

ui <- dashboardPage(
  dashboardHeader(title = "Biodiversity"),
  dashboardSidebar(
    
    actionButton("action","Submit")
    
    
  ),
  dashboardBody(
    useShinyjs(),
    
    show(
      div(id='text_div',
          verbatimTextOutput("text")
      )
    ),
    uiOutput("help_text"),
    plotlyOutput("plot")
  )
)

server <- function(input, output) {
  output$help_text <- renderUI({
    HTML("<b>Click 'Show plot' to show the plot.</b>")
  })
  
  
  react<-eventReactive(input$action,{
    hide("help_text")
    
    omited <-subset(omited, omited$scientificName %in% isolate(input$sci)&omited$verbatimScientificName %in% isolate(input$ver))
  })
  
  
  
  
}

shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r shiny shinyjs


    【解决方案1】:

    你不能在ui中使用show(),这些功能是在服务器中使用的。删除它,它的工作原理。示例:

    ## app.R ##
    library(shiny)
    library(shinydashboard)
    library(dplyr)
    library(shinyjs)
    library(plotly)
    
    ui <- dashboardPage(
      dashboardHeader(title = "Biodiversity"),
      dashboardSidebar(
        
        actionButton("action","Submit")
        
        
      ),
      dashboardBody(
        useShinyjs(),
        
          div(id='text_div',
              verbatimTextOutput("text")
          )
        ,
        uiOutput("help_text"),
        plotOutput("plot")
      )
    )
    
    server <- function(input, output) {
      output$help_text <- renderUI({
        HTML("<b>Click 'Show plot' to show the plot.</b>")
      })
      
      
      observeEvent(input$action,{
        hide("help_text")
        
      
      output$plot <- renderPlot({
        plot(1)
      })
      
      
    })}
    
    shinyApp(ui = ui, server = server)
    

    输出:

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-21
    • 2021-02-24
    • 1970-01-01
    • 2019-12-21
    • 2017-03-03
    • 2019-07-16
    • 2015-04-13
    • 2019-06-21
    相关资源
    最近更新 更多