【问题标题】:Result in a separate page in R shiny在 R 中生成一个单独的页面
【发布时间】:2019-06-25 09:40:08
【问题描述】:

我希望当我单击搜索按钮时在单独的页面上显示结果,而不是在同一页面上。 我已经尝试了两个代码第一个:

用户界面:

ui = fluidPage(
  theme = shinytheme("cerulean"),
  mainPanel(

    div(align = "center", style="margin-left:500px",
        radioButtons("typeInput", "Extract tweets by: ",list("Hashtag" = "hashtag", "Twitter Username"= "username"),inline=T),
          textInput("hashtagInput", "Enter search string","", placeholder = "input search string"),
        conditionalPanel(
          condition = "input.typeInput == 'username'",
          textInput("usernameInput", "Username", placeholder = "input username")),
        sliderInput("numberInput", "Select number of tweets",min = 0, max = 3000, value = 100),
          br(),
        actionButton("goButton", "Search", icon("twitter"),
                     style="color: #fff; background-color: #337ab7"),
        uiOutput("pageStub")
    )))

服务器:

server = function(input, output){
  data = eventReactive(input$goButton, {

    if (input$typeInput == "hashtag") {
      tweetOutput = searchThis(search_string = input$hashtagInput,
                                      number.of.tweets = input$numberInput)} 
    else if (input$typeInput == "username") {
      tweetOutput = userTL(user.name = input$usernameInput,number.of.tweets = input$numberInput)}
    else {}
    library(twitteR)
    df.tweets = data.frame(tweetOutput)
    tweetOutput = df.tweets})
  uiOutput(
    output$pageStub <- renderUI(
      fluidPage(
        fluidRow(
          renderDataTable({data()}, options = list(lengthMenu = c(10, 30, 50), pageLength = 5))))))}

但它会在此处显示的同一页面上显示结果

我尝试了shinyBS库的第二个代码,但我认为窗口太小了

用户界面:

ui = fluidPage(
  theme = shinytheme("cerulean"),
  mainPanel(

    div(align = "center", style="margin-left:500px",
        radioButtons("typeInput", "Extract tweets by: ",list("Hashtag" = "hashtag", "Twitter Username"= "username"),inline=T),
          textInput("hashtagInput", "Enter search string","", placeholder = "input search string"),
        conditionalPanel(
          condition = "input.typeInput == 'username'",
          textInput("usernameInput", "Username", placeholder = "input username")),
        sliderInput("numberInput", "Select number of tweets",min = 0, max = 3000, value = 100),
          br(),
        actionButton("goButton", "Search", icon("twitter"),
                     style="color: #fff; background-color: #337ab7"),

        bsModal("modalExample", "Your result", "goButton", size = "large",dataTableOutput("tweetTable"))
    )))

服务器:

server = function(input, output)
{
  data = eventReactive(input$goButton, {

    if (input$typeInput == "hashtag") 
    {
      tweetOutput = searchThis(search_string = input$hashtagInput,
                                      number.of.tweets = input$numberInput)
    } 
    else if (input$typeInput == "username") 
    {
      tweetOutput = userTL(user.name = input$usernameInput,number.of.tweets = input$numberInput)
    }
    else {}
    library(twitteR)
    df.tweets = data.frame(tweetOutput)
    tweetOutput = df.tweets

  })

 output$tweetTable =renderDataTable({data()}, options = list(lengthMenu = c(10, 30, 50), pageLength = 5))
}

如图所示:

这是我调用的搜索功能:

searchThis = function(search_string,number.of.tweets = 100)
{
  search_tweets(search_string,n = number.of.tweets, lang = "en")
}


userTL = function(user.name,number.of.tweets = 100)
{
  userTimeline(user.name,n = number.of.tweets)
}

还有其他方法可以做到这一点吗? 谢谢你

【问题讨论】:

  • 您能具体说明“单独页面”的含义吗?在闪亮中,您可以使用面板、可折叠对象、弹出窗口......有很多可能性
  • 当我点击按钮时,我的应用程序会显示数据表,但我不需要它在搜索按钮后的同一页面上显示数据表。我需要它在另一个页面上,它更像是我尝试过的弹出窗口但它太小了,我需要窗口来填满所有屏幕

标签: html r shiny


【解决方案1】:

如果你想使用模态框,你可以在 UI 中修改宽度使其全屏显示:

tags$head(tags$style(".modal-dialog{ width:100%; overflow-x: scroll;}"))
# width :100% enables you to choose the width of the modal, it could be 95%,50% ...
# overflow-x:scroll displays a horizontal scrollbar if the content is too large for the modal

你的用户界面会是

ui = fluidPage(
  theme = shinytheme("cerulean"),
  mainPanel(

  tags$head(tags$style(".modal-dialog{ width:100%; overflow-x: scroll;}")),

    div(align = "center", style="margin-left:500px",
        radioButtons("typeInput", "Extract tweets by: ",list("Hashtag" = "hashtag", "Twitter Username"= "username"),inline=T),
          textInput("hashtagInput", "Enter search string","", placeholder = "input search string"),
        conditionalPanel(
          condition = "input.typeInput == 'username'",
          textInput("usernameInput", "Username", placeholder = "input username")),
        sliderInput("numberInput", "Select number of tweets",min = 0, max = 3000, value = 100),
          br(),
        actionButton("goButton", "Search", icon("twitter"),
                     style="color: #fff; background-color: #337ab7"),

        bsModal("modalExample", "Your result", "goButton", size = "large",dataTableOutput("tweetTable"))
    )))

【讨论】:

  • 我得到了这个错误:错误:'closure'类型的对象不是子集
  • 一定是圆括号或方括号的问题,但我不知道在哪里。
  • 太好了,它已接近您的预期?
  • 不,我的意思是 tags$head 部分的问题,它仍然很小
  • 谢谢你的工作我通过阅读这篇文章解决了这个问题stackoverflow.com/questions/34450011/…
猜你喜欢
  • 2020-10-11
  • 1970-01-01
  • 2021-07-17
  • 2022-01-26
  • 2023-01-13
  • 2020-03-28
  • 1970-01-01
  • 2015-10-18
  • 2015-10-12
相关资源
最近更新 更多