R 在图形中使用反应性计算值绘制图形

R 在图形中使用反应性计算值绘制图形,r,shiny,plotly,R,Shiny,Plotly,我只是尝试用三个条带绘制一个绘图图:增益,损耗,和净增益和损耗由sliderInputs控制,而净计算为增益和损耗之间的差值。我目前没有收到任何错误,但列的顺序不正确,列的大小是非反应性的,滑块值也没有正确输入到列中,这可以通过将鼠标悬停在列栏上看到 任何帮助都将不胜感激 library(shiny) library(plotly) ui <- fluidPage( titlePanel(h1("Title")), sidebarLayout( sid

我只是尝试用三个条带绘制一个绘图图:
增益
损耗
,和
<代码>增益和
损耗
sliderInput
s控制,而
计算为
增益
损耗
之间的差值。我目前没有收到任何错误,但列的顺序不正确,列的大小是非反应性的,滑块值也没有正确输入到列中,这可以通过将鼠标悬停在列栏上看到

任何帮助都将不胜感激

library(shiny)
library(plotly)

ui <- fluidPage(
  titlePanel(h1("Title")),
  sidebarLayout(
    sidebarPanel(
      sliderInput(inputId= "gains", label = "Gains", min = 0, max = 10000, value = 3000, step = 1000),
      sliderInput(inputId = "losses", label = "Losses", min = 0, max = 10000, value = 4000, step = 1000),
    ),
    mainPanel(
      tabsetPanel(type = "tabs",
        tabPanel("Tab1",
          plotlyOutput(outputId="graph",height = "600px"))
        
      )
    )
))

server <- function(input, output, session) {
  
  net <- reactive({get(input$gains) - get(input$losses)})
  
  new_data <- reactive({
    data <- c(get(input$gains),get(input$losses),get(net))
  })
  
  output$graph <- renderPlotly({ 
    graph <- plot_ly(
      x = c("Gains", "Losses", "Net"),
      y = ~new_data,
      type = "bar")
  })
}

shinyApp(ui = ui, server =  server)

库(闪亮)
图书馆(绘本)

ui不确定为什么要使用
get()
。但是为了使代码正常工作,您可以去掉
get()
并定义
new\u data
如下:

new_data <- reactive({
    c(input$gains, input$losses, input$gains - input$losses)
  })