เปลี่ยน GGPLOTLY graphs การโต้ตอบอยู่ในสเปนเซอร์รี้ดครับ R เปล่งประกาแอ๊ป

0

คำถาม

ฉันต้องสำหรับ graphs ในของฉันเปล่งประกาแอพเพื่อเปลี่ยนสี(หรือถูกเน้น)เมื่อฉันเมื่อเมาส์ชี้อยู่เหนือพวกมันกับของฉันเมาส์ ฉันจะยังเหมือนพวกเขาต้องแสดงผลเดียวที่คนจำนวนของกราฟของฉันแทนที่จะเป็นนับและ x-ค่า.

นี่คือสิ่งที่มันดูเหมือนของฉันเปล่งประกาแอพ: enter image description here

ทำความเข้าใจกันหน่อยนะว่าฉันจะเหมือนบาร์ที่ฉันป้วนเปี้ยนไปส่องแสงสีน้ำเงิน(หรือสีดำเส้น)และเพื่อนแค่พูดว่า"นับ:61735"โดยไม่บอก"fat_infreq(แข่ง):สีดำ".

ด้านล่างนี้ฉันต้องติดเป็น reproducible ตัวอย่าง:

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ý
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่