Результат на отдельной странице в R блестящий - PullRequest
1 голос
/ 25 июня 2019

Я хочу, чтобы при нажатии на кнопку поиска показывался результат на отдельной странице, а не на этой же странице.Я попробовал два кода первый:

UI:

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))))))}

, но он показывает результат на той же странице, как показано здесь

enter image description here

второй код, который я пробовал в библиотекеBSIX, но я думаю, что окно слишком маленькое

UI:

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))
}

как показано здесь:

enter image description here

и вот функция поиска, которую я вызвал:

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)
}

Есть ли другой способ сделать это?спасибо

1 Ответ

1 голос
/ 25 июня 2019

Если вы хотите использовать модалы, вы можете изменить ширину, чтобы она была полноэкранной со следующей строкой в ​​пользовательском интерфейсе:

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"))
    )))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...