【问题标题】:R Shiny bookmarked URL doesn't renderPlot when link used使用链接时,R Shiny 书签 URL 不会渲染
【发布时间】:2020-08-20 08:10:16
【问题描述】:

我正在尝试使用 R Shiny 将状态添加到 URL 中。该应用程序在首次使用时工作正常,并且保持 URL 正常,但是当我使用 URL 或只是刷新浏览器时,应用程序不显示应该显示的情节。

javascript 控制台说: “错误:util.addPathParams 没有实现转义”

它也会抛出这个错误: 未处理的承诺拒绝:TypeError:a.LegacyGlobal.LP_explicit_ignored 不是函数。 (在 'a.LegacyGlobal.LP_explicit_ignored(document,e)' 中,'a.LegacyGlobal.LP_explicit_ignored' 未定义)

它似乎不喜欢 url 中的文本。

我发现我可以通过在 rstudio 网站上的第 1 课中使用“你好闪亮”并添加书签代码来复制我所犯的任何错误。我用 cmets 标记了编辑的行。 https://shiny.rstudio.com/tutorial/written-tutorial/lesson1/

以下是 shinyapps.io 上的代码: https://jackprior.shinyapps.io/shinypractice/

#attempt to add bookmarking to rstudio lesson 1 and replicate bug
#https://shiny.rstudio.com/tutorial/written-tutorial/lesson1/
library(shiny)
plotmsg =function(txt){return(plot(1:5,main=txt))}  #this is new 
ui <-function(request){ fluidPage(                  #UI wrapped in a function
  titlePanel("Old Faithful Geyser Data"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30),
      textInput("w","name",value="a plot title"), #this is new
      bookmarkButton()      # This is new
    ),

    mainPanel(
      plotOutput("distPlot"),
      plotOutput("plot"),   # This is new
    )
  )
)
}

server <- function(input, output) {
  output$plot <- renderPlot(plotmsg(input$w)) #this is new
  output$distPlot <- renderPlot({
    x    <- faithful[, 2] 
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
  })
}

shinyApp(ui = ui, server = server, enableBookmarking = "url") #this has added parameter

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    这里的问题是使用“w”作为输入参数。 Shinyapps.io 将 &w 编码成它无法评估的东西,并在永久评估中挂起反应。为输入使用不同的名称修复了它。这似乎是一个 shinyapps.io 错误,除非用户应该知道不要使用“w”。我只是用它来最小化 URL 的长度。

    【讨论】:

      猜你喜欢
      • 2020-01-03
      • 2021-03-20
      • 2021-01-29
      • 2019-03-07
      • 2021-03-22
      • 1970-01-01
      • 2020-04-26
      • 1970-01-01
      • 2017-06-22
      相关资源
      最近更新 更多