Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
条形图显示为R_R_Shiny_Shinydashboard_Shinyapps - Fatal编程技术网

条形图显示为R

条形图显示为R,r,shiny,shinydashboard,shinyapps,R,Shiny,Shinydashboard,Shinyapps,我已经开发了一个代码,可以根据反应按钮来显示条形图数据。如果我在条形图上移动光标,我希望知道确切的数字,并将其显示在旁边 代码 library("shiny") data = data.matrix(MY_data[1:4]) ui=fluidPage( # Give the page a title titlePanel("Age ranges according to program"), # Generate a row with a sidebar sideb

我已经开发了一个代码,可以根据反应按钮来显示条形图数据。如果我在条形图上移动光标,我希望知道确切的数字,并将其显示在旁边

代码

library("shiny")
data = data.matrix(MY_data[1:4])
ui=fluidPage(    

  # Give the page a title
  titlePanel("Age ranges according to program"),

  # Generate a row with a sidebar
  sidebarLayout(      

    # Define the sidebar with one input
    sidebarPanel(
      actionButton(inputId = "MBA", label = "MBA"),
      actionButton(inputId = "MSLOD", label = "MSLOD"),
      actionButton(inputId = "MSQBE", label = "MSQBE")



    ),

    # Create a spot for the barplot
    mainPanel(
      plotOutput("hist")  
    )

  )
)




server <- function(input, output) {

  rv <- reactiveValues(data = data[1,1:4])

  observeEvent(input$MBA, { rv$data <- data[1,1:4] })
  observeEvent(input$MSLOD, { rv$data <- data[2,1:4] })
  observeEvent(input$MSQBE, { rv$data <- data[3,1:4] })

  output$hist <- renderPlot({ 

    barplot(rv$data, 
            main=input$radio,
            ylab="Number employees",
            xlab="Ages Range",col=rainbow(4))
  })
}

shinyApp(ui = ui, server = server)

在我们的项目中,我们发现该功能已在plotly中实现:

我已经有一段时间没有使用plotly了,但我相信对于您的应用程序,您会将UI中的
plotOutput
更改为
plotlyOutput
,同样,服务器端也有
renderPlotly
功能

Plotly与标准R绘图有点不同,但它支持更好的开箱即用的交互性,因此如果您打算制作交互式绘图,我建议您使用Plotly

a   b   c  d
5   133 258 106
4   59  60  28
1   34  64  28