R 闪亮-如何显示数据框?

R 闪亮-如何显示数据框?,r,shiny,R,Shiny,我正在使用Shinny,我尝试在Shinny应用程序中将数据框显示为表。我的数据来自在线网站,我使用API获得: make_house_representative_for_state <- function(state = "WA") { base_uri <- "https://api.propublica.org/congress/v1/members/" endpoint <- paste0(base_uri, "house/", state, "/curren

我正在使用Shinny,我尝试在Shinny应用程序中将数据框显示为表。我的数据来自在线网站,我使用API获得:

make_house_representative_for_state <- function(state = "WA") {
  base_uri <- "https://api.propublica.org/congress/v1/members/"
  endpoint <- paste0(base_uri, "house/", state, "/current.json")
  response <- GET(endpoint, add_headers("X-API-Key" = ProPublica_KEY)) 
  df <- content(response, "text")
  dt <- fromJSON(df)
  output <- dt$results
  return(output)
}

在将来发布时,请提供以下信息:

  • 一个完全可复制的示例,意思是:开始完成代码(您缺少
    shinyapp(ui,server)
    ),代码中的数据(您没有提供API密钥,因此代码无法运行),以及您使用的所有库(我在
    shinythemes上出错,因为我没有下载包)(或者知道它来自哪个软件包)
对于您的问题,请使用
renderable
而不是
renderUI
。每个渲染/输出都是一对,
renderUI
tableOutput
不匹配


如果您是Shiny的新手,网上有一些关于服务器和UI如何相互作用的优秀教程()。

以后发布时,请提供以下内容:

  • 一个完全可复制的示例,意思是:开始完成代码(您缺少
    shinyapp(ui,server)
    ),代码中的数据(您没有提供API密钥,因此代码无法运行),以及您使用的所有库(我在
    shinythemes上出错,因为我没有下载包)(或者知道它来自哪个软件包)
对于您的问题,请使用
renderable
而不是
renderUI
。每个渲染/输出都是一对,
renderUI
tableOutput
不匹配

如果您是Shiny的新手,那么在线上有一些关于服务器和UI如何相互交互的很棒的教程()

source("source/propublica.R")

state_representatives <- make_house_representative_for_state()

ui <- fluidPage(

    theme = shinytheme("united"),

    titlePanel("Congressinal Member Information"),

    tabsetPanel(
        type = "tabs", id = "nav_bar",

        tabPanel("State Rrepresentatives",
                 sidebarLayout(
                     sidebarPanel(
                         selectInput("selected_state",
                                     label = h3("Select A State"),
                                     choices = c("AL", "AK", "AZ", "AR", "CA",
                                                 "CO", "CT", "DE", "FL", "GA",
                                                 "HI", "ID", "IL", "IN", "IA",
                                                 "KS", "KY", "LA", "ME", "MD",
                                                 "MA", "MI", "MN", "MS", "MO",
                                                 "MT", "NE", "NV", "NH", "NJ",
                                                 "NM", "NY", "NC", "ND", "OH",
                                                 "OK", "OR", "PA", "RI", "SC",
                                                 "SD", "TN", "TX", "UT", "VT",
                                                 "VA", "WA", "WV", "WI", "WY"),
                                     selected = "WA"
                         )
                     ),

                     mainPanel(
                         tableOutput("state_representatives")
                     )
                 )
        )
    )
)

server <- function(input, output) {

    output$state_representatives <- renderUI({
        state_choose <- input$selected_state
        state_name <- query_to_state_name(state_choose)
        state <- make_house_representative_for_state(state_name)
        return(state)
        # table <- summary_info(state)
    })

}
query_to_state_name <- function(query) {
  t <- paste0("\"", query, "\"")
  return(t)
}