1
$\begingroup$

I would like to position a long text on the right side of this Shiny app, as shown on the screenshot below.

    library(quanteda)
    library(shiny)
    library(tm)
    library(tidytext)
    library(tidyverse)
    library(shinydashboard)
    library(shinythemes)
    
    
    war <- readLines("war.txt")
    
    war_corpus <- corpus(war)
    
    sentences <- tokens(war_corpus,what="sentence")
    
    make_sentences <- function(word) {
      grep(word,sentences,value=TRUE)}
    
    make_sentences("prince")
    
    ui<- shinyUI(fluidPage(
  
  # Application title
  mainPanel(
    img(src='image.jpg', align = "right"),
    
    #titlePanel(title=div(img(src="image.jpg"))),
    
    fluidRow(HTML("<strong> Search Bar")),
    #fluidRow(HTML(" <strong>Date: 06-29-2020</strong>") ),
    
    fluidRow(
      br(),
      p("User Name : ")),
    br(),
    br(),
    
    fluidRow(HTML("<strong>Enter a word.Click \"Next words\" after</strong>") ),
    fluidRow( p("\n") ),
    
    # Sidebar layout
    sidebarLayout(
      
      sidebarPanel(
        textInput("inputString","Enter a word here",value = " "),
        submitButton("Next words")
      ),
      
      mainPanel(
        h4("Are you looking for this ?"),
        tags$style("#mytext {white-space: pre-line;}"),
        verbatimTextOutput("mytext")
        
      )
    )
  )))


    server <- function(input, output, session) {
      output$mytext <- renderPrint({
        
        sentences <- make_sentences(input$inputString)
        length(sentences)
        cat(paste0(1:length(sentences),"  ",sentences,sep= '\n'))
      })
    }
       

enter image description here here is the rcloud link of the project to experiment with : https://rstudio.cloud/project/1497912

$\endgroup$

2 Answers 2

0
$\begingroup$

In your code you use the Sidebar layout which allows only two columns, instead you should use the grid layout to position your elements where you want them, see https://shiny.rstudio.com/articles/layout-guide.html.

You probably need something like this (not tested):

ui<- shinyUI(fluidPage(
  fluidRow(
    column(3,
      # content left 
    ),
    column(5,
      # content centre
    ),
    column(4,
      # content right
    )
  )
)
$\endgroup$
4
  • $\begingroup$ i tried it and I am getting the present "main panel" output as form of single line vertically :( $\endgroup$
    – Vikram
    Commented Aug 3, 2020 at 20:43
  • $\begingroup$ @d123 see edit. $\endgroup$
    – Erwan
    Commented Aug 3, 2020 at 21:06
  • $\begingroup$ i did the same thing and also tried "offset" to give space . gave me same output vertically $\endgroup$
    – Vikram
    Commented Aug 3, 2020 at 21:07
  • 1
    $\begingroup$ @d123 well then you must have a mistake somewhere :) You could try using the example from the Shiny documentation in order to start from a 3 columns layout which works, and then insert your elements one by one. $\endgroup$
    – Erwan
    Commented Aug 3, 2020 at 21:18
0
$\begingroup$

You can run the shiny application, open it in chrome - using google chrome inspector you find the css class titles and add custom css.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.