R Shiny中的rHighchart

问题描述 投票:0回答:1

我想在R中做一个活动仪表盘,我做了一个美国犯罪地图。

highchart() %>%
  hc_title(text = "Total crime in America") %>%
  hc_subtitle(text = "Source: inkomen_crime.xlsx") %>%
  hc_add_series_map(usgeojson, car,
                    name = "state",
                    value = "total_crime",
                    joinBy = c("woename", "state")) %>%
  hc_mapNavigation(enabled = T)

然而,我似乎不能运行它 在R闪亮,用这个代码。

ui <- fluidPage(

  selectInput(inputId = "stateDrop",
              label = "Selecteer een Staat",
              choices = all_states,
              selected = "California",
              multiple=TRUE),

  DT::dataTableOutput(outputId = "America")
)

server <- function(input, output) {
  output$America <- renderDataTable({

    population <- data %>%
      filter(State %in% input$stateDrop)

    datatable(data = population)
  })
}

我觉得我需要引用高图,但我在网上找不到任何东西。我到底做错了什么?请帮助我。

r highcharts shiny rstudio
1个回答
0
投票
library(shiny)
library(highcharter)
library(tidyverse)

# Define UI for application 
ui <- fluidPage(

    selectInput(inputId = "stateDrop",
                label = "Selecteer een Staat",
                choices = all_states,
                selected = "California",
                multiple=TRUE),

    DT::dataTableOutput(outputId = "America"), 

    highchartOutput(outputId = 'plot')
)

# Define server logic 
server <- function(input, output) {
    output$America <- renderDataTable({

        population <- data %>%
            filter(State %in% input$stateDrop)

        datatable(data = population)
    })

    output$plot <- renderHighchart({
        highchart() %>%
            hc_title(text = "Total crime in America") %>%
            hc_subtitle(text = "Source: inkomen_crime.xlsx") %>%
            hc_add_series_map(usgeojson, car,
                              name = "state",
                              value = "total_crime",
                              joinBy = c("woename", "state")) %>%
            hc_mapNavigation(enabled = T)
    })
}

# Run the application 
shinyApp(ui = ui, server = server)
© www.soinside.com 2019 - 2024. All rights reserved.