小编Sam*_*ich的帖子

水平/垂直线图

我正在使用该plotly包,我正在尝试向图表添加水平线.有没有办法用剧情来做?

它可以使用ggplot2和完成ggplotly如下所示的功能:

library(plotly)

p <- ggplot() +
  geom_hline(yintercept = 4) +
  xlim(c(0,10)) +
  ylim(c(0,10))

ggplotly(p)
Run Code Online (Sandbox Code Playgroud)

但我无法将其添加到现有的阴谋图中.

此外,我的图表的轴不固定,因此很难(但不是不可能)只为水平线计算出x和y坐标系,但我宁愿自动添加一个.

我已经查看了y0和dy参数,但我似乎无法获得那些工作的代码.我不太确定他们到底做了什么,但我认为他们可能正在寻找什么?我找不到他们用法的好例子.

r plotly

21
推荐指数
2
解决办法
3万
查看次数

动态绑定到唯一observeEvent的actionButtons

我想生成动态数量的actionButtons,然后让每个生成的按钮将其编号打印到控制台.这是我迄今为止最好的尝试,但我仍然无法获得前10个按钮中的每个按钮的observeEvent来识别按钮点击.如何将按钮绑定到observeEvent?

library(shiny)

ui <- basicPage(
  fluidRow(
    actionButton(inputId = "add_button",
                 label = "Add Button")
    ),
  uiOutput("more_buttons")
)

server <- function(input, output){

  rvs <- reactiveValues(buttons = list(actionButton(inputId = "button1",
                                               label = 1)))

  observeEvent(eventExpr = input$add_button,
               handlerExpr = {
                 len <- length(rvs$buttons) + 1
                 rvs$buttons[[len]] <- actionButton(inputId = paste0("button",len),
                                             label = len)
               })

  output$more_buttons <- renderUI({
    do.call(fluidRow, rvs$buttons)
  })

  # This is the part that doesn't work
  for(ii in 1:10){
    observeEvent(eventExpr = input[[paste0("button",ii)]],
                 handlerExpr = print(ii))
  }

}

shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)

r shiny

5
推荐指数
1
解决办法
927
查看次数

在Shiny App的页面开头将类添加到&lt;html&gt;标签

我想在闪亮的应用程序中呈现的HTML的开头添加一个类到标签。

例如,使用以下代码生成一个基本应用程序:

library(shiny)
ui <- basicPage()
server <- function(input, output){}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)

如果您检查页面,则在开头看到的html标记为:

<html style="overflow: hidden;">
Run Code Online (Sandbox Code Playgroud)

我想做这样的事情:

<html class="myclass" style = "overflow: hidden;">
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以不使用JavaScript?

r shiny

2
推荐指数
1
解决办法
1029
查看次数

标签 统计

r ×3

shiny ×2

plotly ×1