Changer GGPLOTLY les graphes d'interaction dans la R Brillant App

0

La question

Je voudrais pour les graphes dans ma brillante application pour changer la couleur (ou la lumière) lorsque je passe avec ma souris. Je tiens également à seulement sortie le comte de mon graphe, à la place du comte et de la valeur x.

Voici à quoi il ressemble dans mon Brillant Application: enter image description here

Pour être clair, je voudrais que le bar que je suis planant au-dessus de transformer la lumière bleue (ou qui ont un contour noir) et de dire seulement "count: 61735_fr" sans le dire "fat_infreq(course): Noir".

Ci-dessous, j'ai joint un exemple reproductible:

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)

(Pas tous les paquets sont nécessaires, ne peuvent tout simplement pas se souvenir de ceux qui sont à l')

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

La meilleure réponse

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

Dans d'autres langues

Cette page est dans d'autres langues

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