改变GGPLOTLY图表的相互作用的研闪亮的应用程序

0

的问题

我会喜欢的图表中我的闪亮的应用程序来改变颜色(或者是突出强调),当我悬停在他们与我的鼠标。 我还想他们只输出数到我的曲线图,而不是计和x值。

这里是什么它看起来像在我的闪亮的应用程序: enter image description here

到是清楚的,我喜欢的酒吧,我徘徊在把淡蓝色的(或者有一个黑色的大纲)和只说"数:61735",而不说"fat_infreq(比赛):黑色"。

下面,我必须附有一个可重复的例子:

library(shiny)
library(ggplot2)
library(plotly)
library(data.table)
library(shinythemes)
library(forcats)
require(stringi)
require(stringr)
library(scales)
library(ggthemes)
library(plyr)
library(dplyr)
library(readr)
library(tidyr)
library(ggthemes)
library(forcats)
library(xtable)
library(googledrive)
library(googlesheets4)
library(gridExtra)
library(lubridate)
library(DT)
library(vroom)
library(utf8)
library(tableHTML)
library(bslib)
library(devtools)
library(readr)
library(RColorBrewer)

ethnicity <- c("Hispanic", "Non-hispanic","Hispanic","Hispanic","Hispanic","Hispanic","White","White","White","White", 
               "White","Hispanic","Hispanic", "Hispanic","Hispanic","Hispanic","White","White","White","White")
filtered_data <- data.frame(ethnicity)

ui <- fluidPage(

    
    titlePanel("Example"),
        mainPanel(
            plotlyOutput("ethnicity_barplot")
        )
    )

server <- function(input, output) {

    output$ethnicity_barplot <- renderPlotly({
        ggplotly({
            ethnicity_barplot <-ggplot(data = filtered_data, aes(x = fct_infreq(ethnicity))) + 
                geom_bar() + 
                xlab("Ethnicity") + 
                ylab("Number of People") + 
                labs(title = "Ethnicity of Defendants in New York State Courts") + 
                geom_bar(fill = "#327EC2") + 
                theme(panel.background = element_rect(fill = 'white'))+
                theme(plot.background = element_rect(fill = 'white'))+
                theme(plot.title = element_text(hjust = 0.5))+
                theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
                geom_text(stat='count', aes(label=..count..), vjust = -.3)
            
            ethnicity_barplot
        })
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

(不是所有的软件包是必要的,只是不记得那个)

r shiny shiny-reactivity shinyapps
2021-11-24 04:41:27
1

最好的答案

0
library(tidyverse)
library(shiny)
library(plotly)

ethnicity <- c(
  "Hispanic", "Non-hispanic", "Hispanic", "Hispanic", "Hispanic", "Hispanic", "White", "White", "White", "White",
  "White", "Hispanic", "Hispanic", "Hispanic", "Hispanic", "Hispanic", "White", "White", "White", "White"
)
filtered_data <- data.frame(ethnicity)

ui <- fluidPage(
  titlePanel("Example"),
  mainPanel(
    plotlyOutput("ethnicity_barplot")
  )
)

server <- function(input, output) {
  output$ethnicity_barplot <- renderPlotly({
    ggplotly(
      p = {
        ethnicity_barplot <- ggplot(data = filtered_data, aes(x = fct_infreq(ethnicity))) +
          geom_bar() +
          xlab("Ethnicity") +
          ylab("Number of People") +
          labs(title = "Ethnicity of Defendants in New York State Courts") +
          geom_bar(fill = "#327EC2") +
          theme(panel.background = element_rect(fill = "white")) +
          theme(plot.background = element_rect(fill = "white")) +
          theme(plot.title = element_text(hjust = 0.5)) +
          theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
          geom_text(stat = "count", aes(label = ..count..), vjust = -.3)

        ethnicity_barplot
      },
      # only show the y values (counts) as tooltips
      tooltip = "y"
    ) %>%
      # highlight current label
      layout(hoverlabel = list(bgcolor = "orange"), hoveron = list(bgcolor = "red"))
  })
}

# Run the application
shinyApp(ui = ui, server = server)
2021-11-24 08:56:50

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................